2

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
  • 767
  • 1
  • 11
  • 44

2 Answers2

3

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.

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,265
  • 6
  • 21
  • 27
Nishank
  • 129
  • 1
  • 10