1. Ron Calder
  2. SnapDevelop
  3. Tuesday, 24 March 2020 20:19 PM

I get the following message in the browser when running the WebAPI1 solution.  The app compiles in Snap Develop with no errors.  

 

InvalidOperationException: Unable to resolve service for type 'WebAPI1.Services.IDepartmentService' while attempting to activate 'WebAPI1.Controllers.SampleController'.

  • Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired)

  • lambda_method(Closure , IServiceProvider , object[] )

  • Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider+<>c__DisplayClass4_0.<CreateActivator>b__0(ControllerContext controllerContext)

  • Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider+<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)

  • Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)

  • Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()

  • Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()

  • Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)

  • Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)

  • Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()

  • Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()

  • Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)

  • Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.Invoke(HttpContext context)

  • Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Thank you in advance,

Ron

 

Govinda Lopez @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 24 March 2020 21:03 PM
  2. SnapDevelop
  3. # 1
1
Votes
Undo

Hi Ron,

 

I'm not sure what project you are referring to, but try adding the service using the dependency injection. 

services.AddScoped<IDepartmentService, DepartmentService>();

Add this code to your Startup.cs class.

 

Please let me know if this worked for you.

 

 

Regards,

Comment
That worked!

Thank you so much Govinda!
  1. Ron Calder
  2. Wednesday, 25 March 2020 11:20 AM
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.