当我试图用AutoMapper与IIS 7上运行的Web应用程序旨在使用它,映射外部DLL中查看IIS应用程序定义的模型定义域类型。这工作正常,除了当外部的DLL烧结。然后,我得到以下错误:问题与AutoMapper在IIS7使用签名的程序集
AutoMapper.AutoMapperMappingException was unhandled by user code
Message="Trying to map TestLibrary.Source to WebApplication1.Destination.\nUsing mapping configuration for TestLibrary.Source to WebApplication1.Destination\nException of type 'AutoMapper.AutoMapperMappingException' was thrown."
Source="AutoMapper"
StackTrace:
at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context)
at AutoMapper.MappingEngine.Map(Object source, Type sourceType, Type destinationType)
at AutoMapper.MappingEngine.Map[TSource,TDestination](TSource source)
at AutoMapper.Mapper.Map[TSource,TDestination](TSource source)
at WebApplication1._Default.Page_Load(Object sender, EventArgs e)
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: AutoMapper.AutoMapperMappingException
Message="Trying to map TestLibrary.Source to System.Object.\nUsing mapping configuration for TestLibrary.Source to WebApplication1.Destination\nDestination property: Value\nException of type 'AutoMapper.AutoMapperMappingException' was thrown."
Source="AutoMapper"
StackTrace:
at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, Object mappedObject, PropertyMap propertyMap)
at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.Map(ResolutionContext context, IMappingEngineRunner mapper)
at AutoMapper.Mappers.TypeMapMapper.Map(ResolutionContext context, IMappingEngineRunner mapper)
at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context)
InnerException: System.Security.SecurityException
Message="Request failed."
Source="Anonymously Hosted DynamicMethods Assembly"
StackTrace:
at lambda_method(ExecutionScope , Object)
at AutoMapper.Internal.PropertyGetter.GetValue(Object source)
at AutoMapper.Internal.MemberGetter.Resolve(ResolutionResult source)
at AutoMapper.PropertyMap.ResolveValue(Object input)
at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, Object mappedObject, PropertyMap propertyMap)
InnerException:
步骤来重现问题:
1)创建使用Visual Studio 2008的计算机上安装了IIS 7新的Web应用程序。 (我们正在使用Windows 7)。
2)http://www.codeplex.com/AutoMapper下载AutoMapper.dll。 (我们使用的版本是0.4.x.x),并将一个对此Dll的引用添加到您的Web应用程序中。
3)将下面的代码后面的代码中的默认页面:
using System;
using AutoMapper;
using TestLibrary;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Mapper.CreateMap<Source, Destination>();
Mapper.AssertConfigurationIsValid();
var source = new Source {Value = "Automapper works!" };
var destination = Mapper.Map<Source, Destination>(source);
Response.Clear();
Response.ContentType="text/plain";
Response.Write(destination.Value);
Response.End();
}
}
public class Destination
{
public object Value { get; set; }
}
4)创建一个名为“TestLibrary”一个新的类库,并重新命名Class1.cs文件到Source.cs放它的代码如下:
namespace TestLibrary
{
public class Source
{
public object Value { get; set; }
}
}
5)将此库的引用添加到您的Web应用程序中。
6)运行的解决方案,你应该看到“Automapper作品!”输出。
7)为了使它失败,你必须做两件事。
i)将网站配置为在IIS下运行,而不是在Visual Studio开发服务器上运行。 ii)签署TestLibrary组件。 之后,运行解决方案应该会产生上面报告的错误。
有没有人有任何想法如何解决这个问题?我们已经检查并且应用程序正在运行,完全信任IIS管理控制台。
不知道这是否有帮助,但AutoMapper 1.0 RC1可用? – Kane 2009-11-16 18:12:49
我也遇到了与AutoMapper 1.0 RC1相同的问题。 – Zen 2009-11-19 15:14:33
这是非常奇怪的。我会看一看。 – 2009-11-20 01:57:28