AutoMapper 3.0.0 issue: “Could not load file or assembly ‘AutoMapper.Net4′”

Today, I installed AutoMapper 3.0.0 (what a great tool, BTW). I ran into the following issue:

My WPF (.NET 4.5) app has several separate projects, and I want to add AutoMapper (via Nuget) to a project that is not the startup project.

This results in the following error being thrown, upon the first interaction with AutoMapper (typically Mapper.Initialize(…) or Mapper.CreateMap<…>):

Could not load file or assembly 'AutoMapper.Net4, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

When checking the output dir, the AutoMapper.dll and .xml are both copied to the output dir of the startup project, but not AutoMapper.Net4.dll (and yes – ‘copy local’ is set to true).

A post-build event can fix this issue:

copy "$(TargetDir)AutoMapper.Net4.dll" "$(ProjectDir)..\[your startup project's dir]\$(OutDir)"

Maybe not the ideal way to “fix” this – but it works.

Tagged with: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*