署名付きアセンブリを使用する場合、IIS7のAutomApperの問題
-
20-09-2019 - |
質問
私は使用しようとしています AutomApper IIS 7でWebアプリケーションが実行されている場合、それを使用するため、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を使用して新しいWebアプリケーションを作成します。 (Windows 7を使用しています)。
2)autorapper.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)ソリューションを実行すると、「AutomApper Works!」が表示されるはずです。出力。
7)それを失敗させるには、2つのことをする必要があります。
i)Visual Studio Development Serverの代わりにIISで実行するようにWebサイトを構成します。 ii)TestLibraryアセンブリに署名します。その後、ソリューションを実行すると、上記のエラーが発生するはずです。
誰かがこれを回避する方法を知っていますか?私たちはチェックし、アプリケーションはIIS管理コンソールに完全な信頼を遵守して実行されています。
解決
したがって、この例外は、プログラムでラムダ発現を作成してからコンパイルすることから生じます。 Default.aspx.csだけで同じことをしてみてください。これを行う1つの方法は、コードにラムダ式を作成することです。
式> expr =()=> 5;
その後、そうしてください:
var func = expr.compile();
それはあなたにとって失敗しているような線です。
これが機能する場合、次にこのコードをその署名済みアセンブリに入れ、Webアプリケーションからアクセスします。