-
Notifications
You must be signed in to change notification settings - Fork 35
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
Add nullable annotations #300
Comments
@maxkoshevoi Where do you want to have nullable reference types? Is there any use case/scenario where nullable reference would be very helpful for you? Could you provide a code snippet? |
@zhiyuanliang-ms Here's an example where they would be helpful. This is the example code from this repository. If I launch it and don't have a var builder = WebApplication.CreateBuilder(args);
builder.Host.ConfigureAppConfiguration((hostingContext, config) =>
{
var settings = config.AddJsonFile("appsettings.json").Build();
config.AddAzureAppConfiguration(options =>
{
options.Connect(settings["connection_string"]);
});
});
builder.Services.AddAzureAppConfiguration();
var app = builder.Build();
app.UseAzureAppConfiguration();
app.Run(); |
Hi, @maxkoshevoi Thank you for the response.
This is expected, isn't it? Are you suggesting that we should not throw exception when connection string is null/empty, instead, we should just log warning and do nothing? BTW, could you make your code like this by having null check for connection string before call |
Not at all, exception is what I would expect in this situation. No behavioral changes are needed. The only thing left is to tell compiler that All nullable reference types do is give the compiler additional information, so that it can warn users of potential NREs at compile time. Like so:
In this case there won't be an NRE (and if nullable reference types were to be enabled in this package the compiler also wouldn't show the warning, where in the previous example it would which would encourage the user to add the if you mentioned to check connection string for null beforehand) |
I can create the PR for this issue if it's okay |
Hi, @maxkoshevoi
That will be great! Thank you so much. |
@zhiyuanliang-ms could you take a look at the PR please? |
@maxkoshevoi Sure. I was distracted by some other tasks. I didn't put my main focus on .NET provider. I will take a look this RP once I finish my current tasks. |
Please, add support for nullable reference types to these packages.
Microsoft.Extensions.*
dependencies should be annotated in .Net 7 (not all of them are annotated so far)The text was updated successfully, but these errors were encountered: