Domanda

Sto cercando di utilizzare automapper con l'applicazione web in esecuzione su IIS 7. La destinazione d'uso in modo tipi di mappe dominio definito in una DLL esterna per visualizzare i modelli definiti nell'applicazione IIS. Questo funziona bene, tranne quando la dll esterno è bruciacchiato. Allora ottengo il seguente errore:

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: 

Procedura per riprodurre il problema:

1) Creare una nuova applicazione Web utilizzando Visual Studio 2008 su un computer con IIS 7 installato. (Stiamo usando Windows 7).

2) Scarica l'AutoMapper.dll da http://www.codeplex.com/AutoMapper . (Stiamo usando la versione 0.4.x.x) e aggiungere un riferimento a questa DLL per l'applicazione web.

3) Inserire il codice seguente nel codice dietro per la pagina di default:

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) Creare una nuova Libreria di classi denominato "LibreriaProva" e rinominare il file Class1.cs per Source.cs e inserire il seguente codice in:

namespace TestLibrary
{
    public class Source
    {
        public object Value { get; set; }
    }
}

5) Aggiungere un riferimento a questa libreria per l'applicazione web.

6) Eseguire la soluzione e si dovrebbe vedere la "funziona Automapper!" uscita.

7) Per farla fallire, è necessario fare due cose.
   i) Configurare il sito Web per l'esecuzione in IIS anziché il server di sviluppo di Visual Studio.    ii) Firmare l'assembly LibreriaProva.    Dopo di che, in esecuzione la soluzione dovrebbe produrre l'errore sopra riportato.

Qualcuno ha qualche idea di come ottenere intorno a questo? Abbiamo controllato e l'applicazione è in esecuzione con piena fiducia accourding la console di gestione di IIS.

È stato utile?

Soluzione

Quindi, questa eccezione viene da creare un'espressione lambda di programmazione e quindi compilarlo. Si può provare a fare la stessa cosa, solo nei Default.aspx.cs? Un modo per farlo sarebbe quello di creare un'espressione lambda in codice:

Espressione> expr = () => 5;

poi fare:

var func = expr.Compile ();

è una linea proprio come quella che è mancata per voi.

Se questo funziona, allora mi piacerebbe prossimo inserire questo codice in quel assembly firmato, e accedervi dall'applicazione web.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top