Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I just upgraded a solution from .NET framework 4.8 to .NET 6. There are too many warnings, even after I enable nullable in project file

\<Nullable>enable\</Nullable>

Is it safe to suppress all of them?

Warning CS8600 Converting null literal or possible null value to non-nullable type.

Warning CS8601 Possible null reference assignment.

Warning CS8602 Dereference of a possibly null reference.

Warning CS8603 Possible null reference return.

Warning CS8604 Possible null reference argument for parameter

Warning CS8618 Non-nullable field '' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Warning CS8622 Nullability of reference types in type of parameter 'state' of '' doesn't match the target delegate 'WaitCallback' (possibly because of nullability attributes).

Warning CS8625 Cannot convert null literal to non-nullable reference type.

The warnings are showing up because you have enabled the nullable checks. Simply, disable it if you don't want them. momvart Aug 10, 2022 at 9:36 even after enable nullable in project file so enabling the validation of nullable makes you believe that the warnings for nullable go away? Rand Random Aug 10, 2022 at 9:38 Nullable references were designed with great care to allow gradual opt-in, so as to not overwhelm people with barrels of warnings on existing code (as here), which would slow or prevent adoption. This means not using the global enable flag but introducing #nullable enable in individual files, or even individual sections, and introducing annotations before you introduce warnings. The docs have an article on how to go about this. Jeroen Mostert Aug 10, 2022 at 9:41

is it safe to suppress all of them?

Safe is subjective. It will work like it always did; the same null reference bugs will exist with or without the warnings (and the number of those could be zero, if you're always perfect), so if you were happy without the warnings on .NET Framework: you are allowed to disable it.

The warnings are trying to help you , but I do accept that it can be overwhelming when enabling it on an existing large codebase. The option can also be controlled on a file-by-file basis via #nullable enable / #nullable disable if that helps. Personally, I've usually found it is worthwhile taking the time to process the warnings and fix any issues (which often just means marking some fields/parameters/locals as nullable, by adding a ? ) - but: it is up to you whether you decide not to do that - whether than means doing it some time in the future, or never doing it.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .