Skip to content

Conversation

@pranavkm
Copy link
Contributor

@pranavkm pranavkm commented Aug 4, 2020

  • Turn on nullability annotations for public types in M.A.Hosting
  • Turn on nullability annotations for Microsoft.AspNetCore and
    Microsoft.AspNetCore.Server.Abstractions

Contributes to #5680

* Turn on nullability annotations for public types in M.A.Hosting
* Turn on nullability annotations for Microsoft.AspNetCore and
  Microsoft.AspNetCore.Server.Abstractions

Contributes to #5680
@pranavkm pranavkm requested a review from Tratcher as a code owner August 4, 2020 21:39
@ghost ghost added the area-hosting label Aug 4, 2020
@pranavkm pranavkm requested a review from JamesNK August 4, 2020 21:39
@pranavkm pranavkm added this to the 5.0.0-rc1 milestone Aug 4, 2020
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we no longer have the ref project, we can turn on nullability on individual files. Convenient!

/// <returns>The <see cref="IHostBuilder"/> for chaining.</returns>
public static IHostBuilder ConfigureWebHostDefaults(this IHostBuilder builder, Action<IWebHostBuilder> configure)
{
if (configure is null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I bother with this? This would have null-ref (so would have using a null IHostBuilder).

}

private IServiceCollection BuildCommonServices(out AggregateException hostingStartupErrors)
[MemberNotNull(nameof(_options))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It says that the field is non-null at the end of this method call.

{
Console.WriteLine($"Hosting environment: {hostingEnvironment.EnvironmentName}");
Console.WriteLine($"Content root path: {hostingEnvironment.ContentRootPath}");
Console.WriteLine($"Hosting environment: {hostingEnvironment?.EnvironmentName}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can this be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RunAsync does a GetService:

var hostingEnvironment = host.Services.GetService<IHostEnvironment>();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, bug 😄

@ghost
Copy link

ghost commented Aug 4, 2020

Hello @pranavkm!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

Do note that I've been instructed to only help merge pull requests of this repository that have been opened for at least 60 minutes, a condition that will be fulfilled in about 8 minutes. No worries though, I will be back when the time is right! 😉

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

Copy link
Member

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit:

@ghost ghost merged commit bb96535 into master Aug 5, 2020
@ghost ghost deleted the prkrishn/nullable-hosting branch August 5, 2020 01:07
/// <param name="app">A delegate that handles requests to the application.</param>
/// <returns>A started <see cref="IWebHost"/> that hosts the application.</returns>
public static IWebHost Start(string url, RequestDelegate app)
public static IWebHost Start(string? url, RequestDelegate app)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These shouldn't have been made nullable. I know you did that for chaining, but it would be better to override the warning internally.

/// <param name="args">The command line args.</param>
/// <returns>The initialized <see cref="IWebHostBuilder"/>.</returns>
public static IWebHostBuilder CreateDefaultBuilder(string[] args)
public static IWebHostBuilder CreateDefaultBuilder(string[]? args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also only nullable for chaining. Suppress the warning in the caller instead.

/// The name of the authentication scheme for the server authentication handler.
/// </summary>
string AuthenticationScheme { get; }
string? AuthenticationScheme { get; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be null. Where did you see otherwise?

@amcasey amcasey added the area-hosting Includes Hosting label Jun 1, 2023
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-hosting Includes Hosting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants