'Warning ASP5001 'MvcCoreMvcBuilderExtensions.SetCompatibilityVersion(IMvcBuilder, CompatibilityVersion)' is obsolete
In my ASP.NET Core-6 Web API, I installed this NuGet package:
<PackageReference Include="microsoft.aspnetcore.mvc.versioning.apiexplorer" Version="5.0.0" />
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
namespace WebApi.API.V1
{
[ExcludeFromCodeCoverage]
internal static class ApiStartup
{
public static void AddMyApi(this IServiceCollection services)
{
services.AddHealthChecks();
services.AddControllers()
.AddControllersAsServices()
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddJsonOptions(c =>
c.JsonSerializerOptions.PropertyNamingPolicy
= JsonNamingPolicy.CamelCase);
}
}
}
I got these errors:
Warning ASP5001 'CompatibilityVersion' is obsolete: 'This API is obsolete and will be removed in a future version. Consider removing usages.'
Warning CS0618 'CompatibilityVersion.Version_3_0' is obsolete: 'This CompatibilityVersion value is obsolete.'
Warning ASP5001 'MvcCoreMvcBuilderExtensions.SetCompatibilityVersion(IMvcBuilder, CompatibilityVersion)' is obsolete: 'This API is obsolete and will be removed in a future version. Consider removing usages.'
How do resolve it?
Thanks
Solution 1:[1]
Using the appropriate compatibility switches: Allows you to use the latest release and opt out of specific breaking behavior changes.
With ASP.NET Core 3.0, old behaviors supported by compatibility switches have been removed.
And I think, you upgraded to .Net 6 so you can remove this SetCompatibilityVersion, there is no need of this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Manveer Singh |