Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to resolve service for type 'Microsoft.AspNetCore.Cors.Infrastructure.ICorsService

I observe an exception executing the following code:

[<EntryPoint>]
let main argv =                         
    WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .Configure(Action<IApplicationBuilder> configureApp)
        .ConfigureServices(Action<IServiceCollection> configureServices)
        .Build()

Error:

Unable to resolve service for type 'Microsoft.AspNetCore.Cors.Infrastructure.ICorsService

Details:

System.InvalidOperationException: 'Unable to resolve service for type 'Microsoft.AspNetCore.Cors.Infrastructure.ICorsService' while attempting to activate 'Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware'.'

I added the Cors code here:

let configureServices (services : IServiceCollection) =
    ...
    services.AddAuthentication() |> ignore
    services.AddCors |> ignore // Enables CORS

Note:

This all use to work until I added ASP.Net WebAPI support for some json that I was struggling with.

In addition, I also upgraded my Nuget packages to 2.0.

The source code can be found on GitHub.

like image 730
Scott Nimrod Avatar asked Oct 22 '17 13:10

Scott Nimrod


1 Answers

You have to add services.AddCors() in ConfigureServices(IServiceCollection services)

like image 173
sensei Avatar answered Sep 18 '22 00:09

sensei