locked
Unable to use AutoMapper.Mapper.Map method with ASP.NET Core 3.0 Web API RRS feed

  • Question

  • User1768510565 posted

    I am following Pluralsight to learn Web API concepts. I'm trying to map Book entity to the Book DTO object which is defined inside Models folder. But, I am getting below error.

    An object reference is required for the non-static field, method, or property 'Mapper.Map<Book>(object)

    I could not get much help from google as well. When googled for the same, I found two questions here, and here. There, I felt sense but I am not understanding how to apply the same rule in my case.

    Sunday, November 10, 2019 2:08 AM

All replies

  • User1120430333 posted

    Maybe, you need to take Automapper out of the equation for now. The goal is to learn WebAPI concepts for now, becuase you can easily do the mapping yourself manually. 

    To me,  it seems that maybe Book is not an object instance, or 'object' is not a known type. 

    Keep this in mind it's just FYI, the DTO travels usually between the WebAPI client and WebAPI service. So both the client and the service must know about the DTO, which is achievable by creating a classlib project call it Entities or call it whatever you want, but the DTO is kept in the classlib project, and the WebAPI client project and the WebAPI service project have reference to Entities project. And both projects know about the DTO that is in one spot. 

    Sunday, November 10, 2019 1:06 PM