Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullable annotations for Microsoft.Extensions.Configuration #57200

Closed
maxkoshevoi opened this issue Aug 11, 2021 · 10 comments
Closed

Nullable annotations for Microsoft.Extensions.Configuration #57200

maxkoshevoi opened this issue Aug 11, 2021 · 10 comments
Labels
area-Extensions-Configuration untriaged New issue has not been triaged by the area owner

Comments

@maxkoshevoi
Copy link
Contributor

Description

Indexer and GetConnectionString can return null, but they are not annotated to indicate that.

https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Configuration.Abstractions/src/ConfigurationExtensions.cs#L34

Regression?

No

Other information

I'm willing to fix it myself

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Aug 11, 2021
@stephentoub
Copy link
Member

This library hasn't been annotated for nullability at all.

@maxkoshevoi
Copy link
Contributor Author

@stephentoub Would PR that annotates it be accepted? If so, I can do it.

@stephentoub
Copy link
Member

Yes, that would be welcome. Thanks.

@danmoseley
Copy link
Member

Seconding that, we would welcome help annotating our last remaining libraries. This may help you:

https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/api-guidelines/nullability.md

Reach out if you need help from us.

@maxkoshevoi maxkoshevoi changed the title Nullable annotations for IConfiguration this[] and GetConnectionString() Nullable annotations for Microsoft.Extensions.Configuration Aug 12, 2021
@maxkoshevoi
Copy link
Contributor Author

Do you know why Visual Studio 2019 might not generate nullable errors even though nullable is enabled (I tried enabling it everywhere down to `#nullable enabled in the source file)?

VS does generate them for other projects in libraries folder, but not for Configuration ones for some reason.

@ghost
Copy link

ghost commented Aug 12, 2021

Tagging subscribers to this area: @maryamariyan, @safern
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Indexer and GetConnectionString can return null, but they are not annotated to indicate that.

https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Configuration.Abstractions/src/ConfigurationExtensions.cs#L34

Regression?

No

Other information

I'm willing to fix it myself

Author: maxkoshevoi
Assignees: -
Labels:

untriaged, area-Extensions-Configuration

Milestone: -

@stephentoub
Copy link
Member

stephentoub commented Aug 12, 2021

Do you know why Visual Studio 2019 might not generate nullable errors even though nullable is enabled (I tried enabling it everywhere down to `#nullable enabled in the source file)?

The library only has a netstandard2.0 and net461 configuration today:


and we explicitly disable nullable warnings across the repo for such projects:
<NoWarn Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' or '$(TargetFrameworkIdentifier)' == '.NETStandard' or ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '3.0')))">$(NoWarn);nullable</NoWarn>

You can try overriding it by explicitly adding <NoWarn/> to the csproj, but I expect you may run into some additional complications, including the reasons why we suppress them for this configuration. For example, because of lack of annotations on Debug.Assert in the reference assemblies for those target frameworks, the compiler won't consider Debug.Assert(x != null) as part of its nullable flow analysis. The library will probably need a newer target framework added to do this correctly.

@danmoseley
Copy link
Member

Cc @eerhardt

@eerhardt
Copy link
Member

Duplicate of #43605. I'm going to close this issue as there is no reason to track this in multiple places.

The library only has a netstandard2.0 and net461 configuration today

The plan for all Microsoft.Extensions.* libraries is to add a $(NetCoreAppCurrent) TFM to the project. That will allow the compiler to give the correct nullable warnings. (Plus it will give us other benefits as well.) See #54012.

We've been adding the $(NetCoreAppCurrent) TFM to other Extensions libraries as we've needed. e.g. #56324. So @maxkoshevoi, if you were going to add nullable annotations for Configuration, you can just add the new TFM as well in the same PR. But be sure to check all the #ifs are still correct for the new TFM. We've hit that issue in the past when adding new TFMs - for example #56843.

@ghost ghost locked as resolved and limited conversation to collaborators Sep 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Extensions-Configuration untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

5 participants