evgomes / supermarket-api

Simple RESTful API built with ASP.NET Core and .NET 8 to show how to create RESTful services using a decoupled, maintainable architecture.

Home Page:https://medium.com/free-code-camp/an-awesome-guide-on-how-to-build-restful-apis-with-asp-net-core-87b818123e28

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Automapper issue

thedon-chris opened this issue · comments

Startup.cs(36,22): error CS1061: 'IServiceCollection' does not contain a definition for 'AddAutoMapper' and no accessible extension method 'AddAutoMapper' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

Resolved by placing using Automapper; at the top of Startup.cs file

See https://stackoverflow.com/questions/42916182/trying-to-add-automapper-to-netcore1-1-not-recognising-services-addautomapper

Hi @thedon-chris,

I couldn't simulate the problem. Which version of .NET Core do you have installed on your machine?

Please, try running dotnet --version and check if you have version 2.2 or above installed.

If you have the correct version installed, please, try manually restoring dependencies accessing the folder /src/Supermarket.API/ and running dotnet restore.

Let me know if it works, please.

Hi,

I'll close the issue for now since I couldn't simulate it. If the problems happen again, please, reopen it.

Thank you.

The same issue is popping up for me, I have the automapper nuget package installed and also used using.AutoMapper statement, even after all these it doesn't work and my framework is .net core 3.1. Any help would be really appreciated

@subhanisyed17 - I had the same problem until I added AutoMapper.Extensions.Microsoft.DependencyInjection Nuget package.

https://www.nuget.org/packages/AutoMapper.Extensions.Microsoft.DependencyInjection/

@eric-wilson thanks a lot. that did it for me as well!

@eric-wilson thank you , it worked for me as well

@all-contributors please add @thedon-chris for bug
@all-contributors please add @subhanisyed17 for bug
@all-contributors please add @eric-wilson for question

@evgomes

I could not determine your intention.

Basic usage: @all-contributors please add @Someone for code, doc and infra

For other usages see the documentation

@all-contributors please add @eric-wilson for question

If you are having issue with adding your auto mapper, It is better you check through the type and version you added.
If it is not "AutoMapper.Extensions.Microsoft.DependencyInjection", then you won't be able to use "services.AddAutoMapper()".
Sometimes, you might mistakenly add "AutoMapper

If you are having issue with adding your auto mapper, It is better you check through the type and version you added. If it is not "AutoMapper.Extensions.Microsoft.DependencyInjection", then you won't be able to use "services.AddAutoMapper()". Sometimes, you might mistakenly add "AutoMapper

@Sunboy005 Thanks!
This was the trick for me in my Blazor WASM project. I had both AutoMapper and AutoMapper.Extensions.Microsoft.DependencyInjection. I removed the AutoMapper package and everything worked.