khellang / Middleware

Various ASP.NET Core middleware
MIT License
811 stars 112 forks source link

Possible null return value of ProblemDetailsOptions.GetTraceId() #168

Closed maxsenft closed 2 years ago

maxsenft commented 2 years ago

When assigning a function to ProblemDetailsOptions.GetTraceId() which always returns null, the code analyzer throws warning CS8621.

I guess a ? should be added after string in the line

https://github.com/khellang/Middleware/blob/56e449388894e529102cce11002f9cf19f20596b/src/ProblemDetails/ProblemDetailsOptions.cs#L58

So it should look like this:

public Func<HttpContext, string?> GetTraceId { get; set; } = null!;

This should also be reasonable since the result after invoking the function is checked for null:

https://github.com/khellang/Middleware/blob/56e449388894e529102cce11002f9cf19f20596b/src/ProblemDetails/ProblemDetailsOptions.cs#L291-L293

khellang commented 2 years ago

I guess a ? should be added after string in the line

Sounds reasonable to me. Wanna send a PR? πŸ‘ΌπŸ»

khellang commented 2 years ago

Closed with #169. Pushed v6.4.1 to NuGet πŸ˜„