我正在尝试使用 汽车应用程序 在IIS 7上运行Web应用程序的情况下,预期使用它,因此在外部DLL中定义的映射域类型以查看IIS应用程序中定义的模型。这可以正常工作,除非唱歌外部DLL。然后,我会收到以下错误:

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)在安装IIS 7的计算机上,使用Visual Studio 2008创建一个新的Web应用程序。 (我们正在使用Windows 7)。

2)从中下载automapper.dll http://www.codeplex.com/automapper. 。 (我们使用的是0.4.xx版本),并将此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)运行解决方案,您应该看到“自动应用程序!”输出。

7)要使它失败,您必须做两件事。
i)配置网站以在IIS而不是Visual Studio开发服务器下运行。 ii)签署测试仪式组件。之后,运行解决方案应产生上面报告的错误。

有人知道如何解决这个问题吗?我们已经进行了检查,并且该应用程序正在运行,并充分信任IIS管理控制台。

有帮助吗?

解决方案

因此,此例外来自编程创建lambda表达式,然后对其进行编译。您可以尝试在default.aspx.cs中做同样的事情吗?做到这一点的一种方法是在代码中创建lambda表达式:

表达式> expr =()=> 5;

然后做:

var func = expr.compile();

这是一条线,这对您来说是失败的。

如果有效,我将接下来将此代码放入该签名的程序集中,然后从Web应用程序访问它。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top