Why I get exception when I try to use AutoMapper?

Michael

I use AutoMapper in my .NET CORE 2.2 project.

I get this exception:

Missing type map configuration or unsupported mapping. Mapping types: SaveFridgeTypeModel -> FridgeType College.Refrigirator.Application.SaveFridgeTypeModel -> College.Refrigirator.Domain.FridgeType

On This row:

var fridgeType = _mapper.Map<SaveFridgeTypeModel, FridgeType>(model);

Here is defenition of FridgeType class:

public class FridgeType : IEntity , IType
{
    public FridgeType()
    {
        Fridges = new HashSet<Fridge>();
    }
    public int ID { get; set; }
    //Description input should be restricted 
    public string Description { get; set; }
    public string Text { get; set; }
    public ICollection<Fridge> Fridges { get; private set; }
}

Here is defenition of SaveFridgeTypeModel class:

public class SaveFridgeTypeModel
{
    public string Description { get; set; }
    public string Text { get; set; }
}

I add this row:

    services.AddAutoMapper(typeof(Startup));

To ConfigureServices function in Startup class.

UPDATE

I forgot to add mappin configuration to the post.

Here is mapping configs class:

public class ViewModelToEntityProfile : Profile
{
    public ViewModelToEntityProfile()
    {
        CreateMap<SaveFridgeTypeModel, FridgeType>();
    }
}

Any idea why I get the exception above?

Vidmantas Blazevicius

You need to use the type from the assembly where your maps are when registering automapper with DI.

AddAutomapper(typeof(ViewModelToEntityProfile));

If you had multiple assemblies with maps - you could use another overload:

AddAutomapper(typeof(ViewModelToEntityProfile), typeof(SomeOtherTypeInOtherAssembly));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why do I get Argument exception when I try to use "Include("PropertyName")" in query EF?

Why this exception is thrown when I try to use an iterator on this list?

Exception when I try to combine Autofac with AutoMapper`s IMappingEngine

Why I obtain this exception when I try to deploy and execute on TomCat this application that use Spring?

Why I get exception when I try to fetch data from tables that has many to many relationship

Why do I get "Exception; must be caught or declared to be thrown" when I try to compile my Java code?

why do i get exception error when i try output array

Why i get this exception when i try to handle empty value on overflow menu?

Why does the constructor handle the exception but I get a "not handled exception error" when I use it

I get an error when I try to use ROW_NUMBER(), why?

Why do I get invalid syntax when I try to use pandas to run this code?

Why do I get permission denied when I try use "make" to install something?

I get a syntax error when I try to use array map function in Google Scripts. Why?

why do i get an error when i try to use my models?

Why automapper get error when I map model?

Why can't I return when catching an exception with try:?

Why is this throwing an exception when I try to save the attachment from Outlook?

Mismatch Exception Error when I try to use nextint() for File IO

Why I get error when I try to declare local variable?

Why I get error when I try to create stored procedure?

Why do I get an error for "__CrtGetFileInformationByHandleEx " when I try to compile

Why I get an empty file when I try to sort it?

Why I get error when I try to install pyaudio?

Why I get an error when I try to upload a picture

ANull reference exception when I try to get assembly version info

I get an Error when I try to use Firebase Auth

When I try to use scanf with 2 arrays I get an error

Why I get null when try get element by id?

I get this exception when i use this script on my masterpage