asp.netasp.net-core.net-coreswaggeraspnet-api-versioning

The type or namespace name 'ApiVersionDescription' could not be found (are you missing a using directive or an assembly reference?)


I already added the package of Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer, but I'm still getting this error. Is anyone have an idea on how to resolve this issue?Thank you in advance.

Reference: https://www.meziantou.net/versioning-an-asp-net-core-api.htm#integration-with-ope


Solution

  • You haven't said which versions or runtimes you are targeting. I'm going to assume that your project is .NET Core 3.1 or newer and the language is C#. The ApiVersionDesription class is defined in Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer.dll. The following are required to resolve this error message:

    1. Reference the Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer NuGet package
    2. Use the corresponding namespace with using Microsoft.AspNetCore.Mvc.ApiExplorer;

    You said you've already done #1 so I presume the only issue is #2. If you did not add the reference using tooling, it's worth double-checking that the NuGet package is properly referenced and the containing assembly was also added as a reference.

    You also did not mention what your end goal was. 99% of the scenarios that use the API Explorer extensions for API Versioning want to wire up Swashbuckle or some other Open API/Swagger document generator. I would consider reviewing the official API Versioning Swagger Example for ASP.NET Core and cross-reference it with your configuration. It is a working end-to-end solution and should help reveal the step or steps that you're missing.


    UPDATE: If you're using ASP.NET API Versioning >= 6.0.0 then the correct: