我正在尝试在.Net Core 2.2上使用Auto Mapper。
配置:
services.AddAutoMapper(cfg =>
{
cfg.CreateMissingTypeMaps = false;
cfg.ReplaceMemberName("_", "");
cfg.ShouldMapProperty = pi => pi.PropertyType != typeof(List<>);
cfg.CreateMap<bool, string>().ConvertUsing(b => b ? "Y" : "N");
cfg.CreateMap<string, bool>().ConvertUsing(s => s == "Y");
cfg.CreateMap<NuCoreAppUser, APP_USER>()
.ForMember(d => d.APP_USER_ID, opt => opt.MapFrom(src => src.Id))
.ReverseMap();
};
这只是一个用于测试的映射。它在本地运行良好,但是在部署到Azure应用服务时会抛出:
ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'System.Web.IHttpModule' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
System.Reflection.RuntimeAssembly.get_DefinedTypes()
AutoMapper.ServiceCollectionExtensions+<>c.<AddAutoMapperClasses>b__14_2(Assembly a)
System.Linq.Enumerable+SelectManySingleSelectorIterator<TSource, TResult>.ToArray()
System.Linq.Enumerable.ToArray<TSource>(IEnumerable<TSource> source)
AutoMapper.ServiceCollectionExtensions.AddAutoMapperClasses(IServiceCollection services, Action<IServiceProvider, IMapperConfigurationExpression> configAction, IEnumerable<Assembly> assembliesToScan)
AutoMapper.ServiceCollectionExtensions.AddAutoMapper(IServiceCollection services, Action<IMapperConfigurationExpression> configAction)
NuCoreWebBase.Startup.ConfigureServices(IServiceCollection services) in Startup.cs
Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize()
Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
在我的应用程序中找不到任何引用System.Web的地方,也找不到限制Auto Mapper扫描该程序集的方法。
如果我删除了Auto Mapper,则一切正常部署。