Created
April 7, 2022 01:04
-
-
Save siennathesane/1199ee46d24e3997387935b93fa56806 to your computer and use it in GitHub Desktop.
Example of an incorrectly identified `InconsistentlySynchronizedField` warning in ReSharper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Foo { | |
private int[] _arr; | |
private readonly Guid _id; | |
private readonly object _lockObj; | |
public this[int index] { | |
get => _arr[index]; | |
set => Set(index, value); | |
} | |
public Foo(Guid id) { | |
_id = id; | |
_lockObj = new object(); | |
} | |
private void Set(int index, int val) { | |
lock (_lockObj) { | |
// this is throwing InconsistentlySynchronizedField, because it's | |
// part of a locked context, not because there is an actual | |
// synchronization issue. | |
Console.WriteLine($"Guid is {_id.ToString()}"); | |
_arr[index] = value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment