Home > OS >  how to fix all Non-nullble warnings in my project
how to fix all Non-nullble warnings in my project

Time:10-12

I have the Asp.Net Core project with

 <Nullable>enable</Nullable>

I had added Identity and got 195 warnings. How can I fix that without rewriting all the code by myself?

CodePudding user response:

From the Microsoft documentation:

https://docs.microsoft.com/en-us/dotnet/csharp/nullable-migration-strategies

Nullable reference types enable you to declare if variables of a reference type should or shouldn't be assigned a null value. The compiler's static analysis and warnings when your code might dereference null are the most important benefit of this feature. Once enabled, the compiler generates warnings that help you avoid throwing a System.NullReferenceException when your code runs.

If your codebase is relatively small, you can turn on the feature in your project, address warnings, and enjoy the benefits of the improved diagnostics. Larger codebases may require a more structured approach to address warnings over time, enabling the feature for some as you address warnings in different types or files.

"Warnings" are generally a "Good Thing".

But if you're not prepared to update your code base, and/or you don't believe most of these warnings are valid (that's entirely possible), then you should probably remove <Nullable>enable</Nullable> from your project settings.

Please be sure to review all of these suggestions:

  • Related