WPF Prism application - Automapper causes System.Core load failure

孤街浪徒 提交于 2019-12-11 06:47:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!