Search code examples
asp.net-coreautomapperupgrade.net-7.0

AutoMapper error after upgrading to .NET 7


I upgraded a .NET Core 2.1 app to .NET 7 and upgraded the AutoMapper version that was being used to the latest version.

I had to change the ResolveUsing calls to MapFrom as the earlier was not available in the new version of the AutoMapper.

Now when I run the app, I am getting the following error:

Error: Method not found: '!!1 AutoMapper.IMapper.Map(!!0)'.

I have found that it's happening to Methods that are using the automapper where it's using a custom method:

.ForMember(dest => dest.RoleName, opt => opt.MapFrom(src => CustomResolvers.GetRoleName(src)))

The above CustomResolvers is a static public class and GetRoleName is a static method. This was fine using ResolveUsing in the earlier version of automapper but changing to MapFrom, causes the above mentioned error.

Any help would be greatly appreciated. Thanks Angelo


Solution

  • It was just that a project that I was referencing was using the Automapper and that had the older version of Automapper.

    Once I updated the Automapper for that project, everything is fine.

    Thanks Angelo