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.
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.
AutoMapper doesn't work in asp net core 5.0.
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));
I just ran into this problem and came to know that You need to include following Nuget package AutoMapper.Extensions.Microsoft.Dependencyinjection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With