include::../why-dotnet.adoc[]

== How to fix it

=== Code examples

==== Noncompliant code example

[source,csharp,diff-id=1,diff-type=noncompliant]
----
public class Sample
{
    private readonly StackOverflowException myLock = new();

    public void Go()
    {
        lock (myLock) // Noncompliant
        { 
            // ...
        } 
    }
}
----

==== Compliant solution

[source,csharp,diff-id=1,diff-type=compliant]
----
public class Sample
{
    private readonly object myLock = new();

    public void Go()
    {
        lock (myLock) 
        { 
            // ...
        }
    }
}
----

include::../rspecator.adoc[]

include::../resources-dotnet.adoc[]