khellang / Middleware

Various ASP.NET Core middleware
MIT License
806 stars 110 forks source link

Ambiguous invocation in .Net 7 #187

Open akshaybabloo opened 1 year ago

akshaybabloo commented 1 year ago

Trying to experiment with .Net 7 and I get this error when building it

  Program.cs(76, 18): [CS0121] The call is ambiguous between the following methods or properties: 'Microsoft.Extensions.DependencyInjection.ProblemDetailsServiceCollectionExtensions.AddProblemDetails(Microsoft.Extensions.DependencyInjection.IServiceCollection)' and 'Hellang.Middleware.ProblemDetails.ProblemDetailsExtensions.AddProblemDetails(Microsoft.Extensions.DependencyInjection.IServiceCollection)'

I added it to my builder services like this:

builder.Services.AddProblemDetails();

Workes fine on .Net 6

This is a conflict with the newly introduced AddProblemDetails in Microsoft.Extensions.DependencyInjection.ProblemDetailsServiceCollectionExtensions.AddProblemDetails

More info on their blog https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-dotnet-7-preview-7/#new-problem-details-service

NzKyle commented 1 year ago

I managed to get around this by doing:

ProblemDetailsExtensions.AddProblemDetails(services);

Instead of:

services.AddProblemDetails();
cheesi commented 1 year ago

You can also use a using: using ProblemDetailsOptions = Hellang.Middleware.ProblemDetails.ProblemDetailsOptions;

VictorioBerra commented 1 year ago

Just using:

using ProblemDetailsOptions = Hellang.Middleware.ProblemDetails.ProblemDetailsOptions;

Dot not resolve it for me. I had to do the ProblemDetailsExtensions.AddProblemDetails(services);