error CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' a nnotations context. #4784
-
I'm trying to use the I want to fix some of the code with annotations and without having Context: When I do this, which is having few nullable annotations, but the feature disabled, I get
Which breaks my expectation that we want null safe code at some point, without a big bang change, and without having to single handedly put pragma in all the files (1 per class roughly) of a project. What was the motivation for this error? Is the feature only geared toward "new project will be null safe sometimes but old projects need to do big bang editing of all files at once"? I'm not inclined to sprinkle "#nullable" pragmas in thousands of files, one by one, and then again, remove those, in thousands of files when the code reach the state of "null references all annotated". Am I missing something? Edit: basically I get the feeling I'm getting punished for daring to use "warning as error" and trying to get familiar with the null annotation syntax by starting using the annotations without enabling the feature. Solution: use <PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'">
<LangVersion>latest</LangVersion>
<WarningsNotAsErrors>$(WarningsNotAsError);8632;8618;8600;8602;8625</WarningsNotAsErrors>
<Nullable>warnings</Nullable>
</PropertyGroup> |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
Have you checked out the You could also try |
Beta Was this translation helpful? Give feedback.
-
I'm seeing issues with pre dotnet SDK project files, I'm in a large solution with a mix of both and despite the nullable feature picks up, the What is the recommended approach to make progress in mixed SDK project format solution? I can't easily upgrade the projects and I want to rely on |
Beta Was this translation helpful? Give feedback.
-
It's not clear from the thread so far whether you are using For gradual migration, I've added Have you tried this? |
Beta Was this translation helpful? Give feedback.
Have you checked out the
<WarningsNotAsErrors>
option for your csproj?You could also try
<Nullable>annotations</Nullable>
or any of the other options.