Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to add AutoMapper to .NetCore1.1 - not recognising services.AddAutoMapper()

I've installed the following Nuget packages into my project:

  • Automapper
  • AutoMapper.Extensions.Microsoft.DependencyInjection

I have added the line to ConfigureServices in Startup.cs.

public void ConfigureServices(IServiceCollection services) {     // Add framework services.     services.AddMvc();     // . . .     services.AddAutoMapper(); } 

I'm still getting a red line under services.AddAutoMapper(). It says:

The Call is ambiguous between the following methods or properties: ServiceCollectionExtensions.AddAutoMapper(IServiceCollection, params Assembly[]) and ServiceCollectionExtensions.AddAutoMapper(IServiceCollection, params Type[])

Why is this happening? All the .NET Core add automapper guides I've read show to do it this way.

like image 488
magna_nz Avatar asked Mar 21 '17 00:03

magna_nz


People also ask

Does AutoMapper work with .NET core?

AutoMapper is a ubiquitous, simple, convention-based object-to-object mapping library compatible with.NET Core. It is adept at converting an input object of one kind into an output object of a different type. You can use it to map objects of incompatible types.

Does AutoMapper support .NET 5?

AutoMapper doesn't work in asp net core 5.0.


2 Answers

I'm running into the same issue, so checked the sourcecode and tests for guidance. It seems you need to pass either an assembly or a "marker type" inside the assembly you want scanned. I went for the following as my Profile classes are in the same assembly as the Startup class.

services.AddAutoMapper(typeof(Startup)); 
like image 43
Robert Massa Avatar answered Sep 18 '22 06:09

Robert Massa


I just ran into this problem and came to know that You need to include following Nuget package AutoMapper.Extensions.Microsoft.Dependencyinjection

like image 163
Ikram Shah Avatar answered Sep 21 '22 06:09

Ikram Shah