问题
I have a WPF 4.5 Prism project which works fine until I add Automapper 3.0 to it. When I add Automapper to my DAL in order to translate from Entity Framework objects to DTOs, the application fails in runtime, seemingly immediately after shell creation. I read somewhere that Automapper isn't completely deployed in some cases, so I have added references to Automapper and Automapper.Net4 to the Shell project as well to make sure everything is deployed.
This is the error message I get:
Could not load file or assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The system cannot find the file specified.
Here is the code I added that causes the exception:
namespace DAL
{
[PartCreationPolicy(CreationPolicy.NonShared)]
[Export(typeof(ICampaignActionDataAccess))]
public class CampaignActionDataAccess : ICampaignActionDataAccess
{
public CampaignActionDataAccess()
{
//if (Mapper.FindTypeMapFor<CampaignAction, CampaignActionDTO>() == null)
// Mapper.CreateMap<CampaignAction, CampaignActionDTO>();
//if (Mapper.FindTypeMapFor<CampaignActionGroup, CampaignActionGroupDTO>() == null)
// Mapper.CreateMap<CampaignActionGroup, CampaignActionGroupDTO>();
//if (Mapper.FindTypeMapFor<CampaignActionDescriptor, CampaignActionDescriptorDTO>() == null)
// Mapper.CreateMap<CampaignActionDescriptor, CampaignActionDescriptorDTO>();
}
public IEnumerable<CampaignActionDTO> GetAllActiveCampaignActions()
{
//using (var db = new CampaignActionEntities())
//{
// var actions = (from ca in db.CampaignActions.Include(d => d.CampaignActionDescriptors)
// where ca.IsValid == true
// select ca).ToList();
// return Mapper.Map<IEnumerable<CampaignActionDTO>>(actions);
//}
throw new NotImplementedException();
}
}
}
来源:https://stackoverflow.com/questions/18959285/wpf-prism-application-automapper-causes-system-core-load-failure