Compiler error (Init-only setters) when using LangVersion 8.0 in a .NET Standard 2.0 library
See original GitHub issueDescription (optional)
I got compiler error CS8400 Feature 'init-only setters' is not available in C# 8.0. Please use language version 9.0 or greater.
when compiling a .NET Standard 2.0 class library with C# 8.0 as the LangVersion
. Upgrading to 9.0 fixed the issue but should not be nesessary.
Reproduction Steps
Create a Class Library using the following .csproj
content and this class Product.cs
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PolySharp" Version="1.6.0" />
</ItemGroup>
</Project>
using System.Diagnostics.CodeAnalysis;
namespace ClassLibrary19 {
public class Product {
[AllowNull]
public string ProductName { get; set; }
}
}
Expected Behavior
No compiler error
Actual Behavior
error CS8400
System info
This section should contain useful info such as:
- PolySharp NuGet version 1.6
Additional context (optional)
Any additional info that might be useful to resolve the issue.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
After update to VS 16.9.0: Feature 'init-only setters' is not ...
This looks to be a badly-advised breaking change in the library, that was added at the end of January and which has already...
Read more >C# 9 Records and Init Only Settings Without .NET 5
To use a public or protected property with an init only setter, the consumer must be using a C# compiler that supports C#...
Read more >Why isn't .NET Standard 2.0 used as the default compared ...
I know that .NET Framework and .NET Core are the implementation frameworks, while .NET Standard 2.0 is the specification that the frameworks ...
Read more >Init Properties and modreq · Issue #3376 · dotnet/csharplang
The plan is to have the compilers (C#, VB and F#) that ship with .NET 5 to be able to consume init-only properties...
Read more >Init only setters - C# 9.0 draft feature specifications
This feature specification describes the rules for 'init' only setters in properties. These can be set only as part of an instantiation, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you! It is really great to have this. I was using this Nullable package before. But PolySharp has much more. Happy!
Thanks for this tip. I will set the PrivateAssets=“all”.