I had this C# structure that was building in VS2022 literally up until last night when I upgraded from version 17.0.5 to 17.1
internal struct RoutineSettings
{
public bool Show { get; set; } = true;
public ShapeType PreferredShapeType { get; set; } = ShapeType.None;
}
(ShapeType is just an enum).
After the upgrade, I get this error:
error CS8983: A 'struct' with field initializers must include an explicitly declared constructor.
The explanation is straightforward enough. But since this code executed just fine before I am confused.
- Is the compiler wrong?
- Is it a true language requirement that the compiler was just failing to check for until now?
If the correct answer is #2, it begs the question why is this a requirement? Why is it needed? Because when I "fixed" it, the fix seemed pointless. I just added an empty default constructor:
internal struct RoutineSettings
{
public RoutineSettings() { }
public bool Show { get; set; } = true;
public ShapeType PreferredShapeType { get; set; } = ShapeType.None;
}
And now my code builds again. Why would I need this when it does nothing?