Nullable Reference Type annotations #3092
Labels
💡 Enhancement
Issues that are feature requests for the drivers we maintain.
🆕 Triage Needed
For new issues, not triaged yet.
Is your feature request related to a problem? Please describe.
C# 8.0 introduced Nullable Reference Types. Since .NET Core 3.0, the runtime has been annotating its assemblies - this was tracked for .NET 5.0 with dotnet/runtime#2339, and from .NET 6.0 onwards with dotnet/runtime#41720.
The SqlClient driver doesn't have Nullable Reference Type annotations. The prevents upstream assemblies from performing a complete set of null-safety checks. It also means that the compiler support for null-safety checks within these projects is switched off, increasing the risk of unexpected NullReferenceExceptions.
Describe the solution you'd like
I'd like to see the SqlClient assemblies annotated in such a way to enable NRT support. This will enable those two cases: the compiler will be able to use static flow analysis to perform null-safety checks within the project, and for libraries which reference SqlClient.
Additional context
There are several code analysis attributes which only exist in .NET Core. We might need to replicate the API surface of these attributes in the same way that Newtonsoft.Json does (link.)
I'd propose that we copy the .NET Runtime approach of working upwards from base dependencies. Most of these dependencies were simple enough that the codebase merges have already been performed for them. NRT annotations in the public-facing/complex types should probably wait until those types' codebases are merged.
Any NRT annotation work will probably be made slightly more complex by our use of three SNIs: native, managed and SqlClientX. We'd need to make sure that null-safety checks are identical across these SNIs, and that might need changes within the native SNI.
The text was updated successfully, but these errors were encountered: