Need A Reliable Software Technology Partner?
00D
00H
00M
00S
Explore Now
← Back to Articles
Development / backend API development

.net core api creation isuess &fixes | System.InvalidOperationException: Unable to resolve service for type

PPrem1 Min Read
.net core api creation isuess &fixes | System.InvalidOperationException: Unable to resolve service for type

Error: response status is 500

Response body

Download

System.InvalidOperationException: Unable to resolve service for type ‘Crowdrob.BAL.Interfaces.IOrderItemsService’ while attempting to activate ‘Crowdrob.API.Controllers.OrderItemsController’.

Get Expert Help to Debug, Fix & Scale Your .NET Applications

at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ThrowHelperUnableToResolveService(Type type, Type requiredBy)

at lambda_method10(Closure, IServiceProvider, Object[])

at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)

Solutions:

Issues coming because you forgot to add the services into the program.cs file:

builder.Services.AddScoped<IOrderItemsService, OrderItemsService>();

builder.Services.AddScoped<IPaymentService, PaymentService>();

Issues:

Cannot insert explicit value for identity column in table 'tblOrderItems' when IDENTITY_INSERT is set to OFF.
solution: You can check may in primary identity key you are trying to put value, it is auto generated,

Frequently Asked Questions

What is .net core api creation isuess &fixes | System.InvalidOperationException: Unable to resolve service for type?

Getting “Unable to resolve service for type” in .NET Core? Learn how to fix this 500 error by properly registering your services in Program.cs using AddScoped.

Reader Responses

Join the Conversation

Fix .NET Core 500 Error: Unable to Resolve Service