Version Used:
Visual Studio 2026 v18.0.0
.NET 10
Steps to Reproduce:
-
Use the following minimal code sample:
public sealed class Test
{
private static Test? s_instance;
public static Test Instance => s_instance!;
public Test()
{
s_instance = this;
}
}
-
Observe that the analyzer reports IDE0032 for s_instance.
-
Apply the code fix suggested by the IDE.
-
Observe that the produced code cannot be compiled.
Diagnostic Id:
IDE0032: Use auto-implemented property
Expected Behavior:
The code fixer should not create invalid code that will not compile.
Actual Behavior:
The code fixer rewrites the class to:
public sealed class Test
{
public static Test Instance => field!;
public Test()
{
Instance = this;
}
}
This results in the following compiler error:
CS0200: Property or indexer 'Test.Instance' cannot be assigned to — it is read only