Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Deployed WebAPI project fails to perform dependency injection for middleware

$
0
0

I'm deploying a site to Windows Server 2012 R2, and I get this error from the deployed site:

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

Microsoft.Extensions.Internal.ActivatorUtilities+ConstructorMatcher.CreateInstance(IServiceProvider provider)

InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Cors.Infrastructure.ICorsService' while attempting to activate 'Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware'.
Microsoft.Extensions.Internal.ActivatorUtilities+ConstructorMatcher.CreateInstance(IServiceProvider provider)
Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+<>c__DisplayClass3_0.<UseMiddleware>b__0(RequestDelegate next)
Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build()
Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

I took out app.UseCors() to see what would happen and redeployed, and I realized that for every middleware I'm using that uses dependency injection, I'm getting the same type of error (it will be a different service and different middleware, but essentially the same error).  If I take all the middleware out of the configuration, the webapi finally does run.  

This isn't an issue when I run the webapi application locally.  Why is it behaving this way when deployed?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>