문제

나는 사용하려고합니다 automapper IIS 7에서 웹 애플리케이션이 실행되면 의도 된 것은 IIS 응용 프로그램에 정의 된 모델을보기 위해 외부 DLL에 정의 된 맵 도메인 유형을 사용합니다. 외부 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을 사용하여 새로운 웹 응용 프로그램을 만듭니다. (우리는 Windows 7을 사용하고 있습니다).

2) Automapper.dll을 다운로드하십시오 http://www.codeplex.com/automapper. (우리는 버전 0.4.xx를 사용하고 있습니다.) 웹 응용 프로그램 에이 DLL에 대한 참조를 추가하십시오.

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)이 라이브러리에 대한 참조를 웹 응용 프로그램에 추가하십시오.

6) 솔루션을 실행하면 "Automapper Works!"가 보일 것입니다. 산출.

7) 실패하기 위해서는 두 가지 일을해야합니다.
i) Visual Studio Development Server 대신 IIS에서 실행되도록 웹 사이트를 구성합니다. ii) TestLibrary 어셈블리에 서명하십시오. 그 후 솔루션을 실행하면 위에서보고 된 오류가 생성됩니다.

누구 든지이 문제를 해결하는 방법이 있습니까? 우리는 확인했고 IIS 관리 콘솔을 위반하는 완전한 신뢰로 응용 프로그램이 실행 중입니다.

도움이 되었습니까?

해결책

따라서이 예외는 람다 표현식을 프로그래밍 방식으로 만들고 컴파일하는 것입니다. Default.aspx.cs에서 똑같은 일을 시도 할 수 있습니까? 이를 수행하는 한 가지 방법은 코드에서 Lambda 표현식을 만드는 것입니다.

expression> expr = () => 5;

그런 다음 :

var func = expr.compile ();

그것은 당신에게 실패하는 것과 같은 줄입니다.

이것이 작동하면 다음 에이 코드를 서명 된 어셈블리에 넣고 웹 응용 프로그램에서 액세스 할 것입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top