3

In my nugent panel, I installed

AutoMapper v7.0.1 AutoMapper.extensions.microsoft.dependencyinjection v5.0.1

In my Startup.cs,

I added

Services.AddAutoMapper();

but the compiler gives

Severity    Code    Description Project File    Line    Suppression State
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?)  OPEApiService   J:\Projects\OPEApiService\OPEApiService\Startup.cs  58  Active

I tried clean, rebuild, close and reopen VS.

Any help is appreciated.

Thanks

user1250264
  • 897
  • 1
  • 21
  • 54

3 Answers3

8

This could be a compatibility issue between the two packages. If you have both the AutoMapper and AutoMapper.extensions.microsoft.dependencyinjection packages installed, remove them and add only the AutoMapper.extensions.microsoft.dependencyinjection. It has a dependency on the AutoMapper package.

I had this same issue and was able to resolve it.

2

You need to add a reference to :

$ AutoMapper.Extensions.Microsoft.DependencyInjection

Search it using NuGet Packages Manager and install it.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Shalim Ahmed
  • 259
  • 3
  • 6
1

You missed the restore step. From the root directory where the solution file exists, run following command:

dotnet clean
dotnet restore
dotnet build

Build error I received after including the services.AddAutoMapper();

Build error

Then after executing the series of command, got it running.

Success

Greenonline
  • 1,330
  • 8
  • 23
  • 31
Nishank
  • 159
  • 1
  • 11