0

I need to configure the CORS of multiple Apis with the same setting. So, I decided to create a class library and wrap the IServiceCollection.AddCors in a new extension method push it to my package repository (Nexus), and use the DLL for all of my APIs. However, I could not find the package that the AddCors function belongs to.

I Added

  • Microsoft.Extensions.DependencyInjection
  • Microsoft.Extensions.DependencyInjection.Abstractions

But I there is this error:

CorsInjection.cs(9, 33): [CS1061] 'IServiceCollection' does not contain a definition for 'AddCors' and no accessible extension method 'AddCors' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

How can I figure it out in dotnet core 8 class library?

2
  • 1
    Make use of the API explorer: learn.microsoft.com/en-gb/dotnet/api/?term=AddCors . You'll see it is an extension method within package Microsoft.AspNetCore.App.Ref (which, IIRC, is implicitly referenced in an ASP.NET Core project.... but not a class library). Commented Apr 29, 2024 at 14:56
  • I tried to install but Microsoft.AspNetCore.App.Ref it failed because of this error: 'DotnetPlatform' is not supported by the project Commented Apr 30, 2024 at 2:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.