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

HttpResponse.ContentType is marked as String but is null sometimes #42222

Closed
1 task done
Patrick8639 opened this issue Jun 16, 2022 · 4 comments
Closed
1 task done

HttpResponse.ContentType is marked as String but is null sometimes #42222

Patrick8639 opened this issue Jun 16, 2022 · 4 comments
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved

Comments

@Patrick8639
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In some cases, the value of HttpResponse.ContentType can be null, but the property is defined as String and not String?.
The problem is that, if we test whether ContentType is null, Intellisense complains that the value cannot be null.

Expected Behavior

Either one:

  • Define the property value as String?.
  • Define a default non-null value is the constructor(s).

Steps To Reproduce

This is the minimal code to show the problem.

Implement an endpoint to catch OPTIONS request:

public static class OptionsRequest
{
  private static Task ProcessAsync (
    HttpContext context
  )
  {
    var Response = context.Response;
  }
}

Register the endpoint:

app.UseEndpoints (
    endpoints =>
    {
      endpoints.MapMethods ("/{*all}", new String [] { "OPTIONS" }, ProcessAsync)
    }
);

When the OptionsRequest.ProcessAsync method is called, Response .ContentType is null.

Exceptions (if any)

No response

.NET Version

6.0.6

Anything else?

ASP.NET Core 6.0.6
VS pro 17.2.4

dotnet --info:

.NET SDK (reflecting any global.json):
 Version:   6.0.301
 Commit:    43f9b18481

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22000
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.301\

Host (useful for support):
  Version: 6.0.6
  Commit:  7cca709db2

.NET SDKs installed:
  5.0.301 [C:\Program Files\dotnet\sdk]
  5.0.409 [C:\Program Files\dotnet\sdk]
  6.0.100-rc.2.21505.57 [C:\Program Files\dotnet\sdk]
  6.0.301 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
@campersau
Copy link
Contributor

I guess this is already fixed in .NET 7 #35547

public abstract string? ContentType { get; set; }

@Patrick8639
Copy link
Author

@campersau
Yes, but the problem is here in .NET 6...

@BrennanConroy
Copy link
Member

Yes, but the problem is here in .NET 6...

It's unfortunate, but we can't make API changes in a patch. You'll either need to use .NET 7 or suppress the warning.

@BrennanConroy BrennanConroy added the ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. label Jun 16, 2022
@ghost ghost added the Status: Resolved label Jun 16, 2022
@ghost
Copy link

ghost commented Jun 17, 2022

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed Jun 17, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jul 18, 2022
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved
Projects
None yet
Development

No branches or pull requests

5 participants