简体   繁体   中英

Automapper Error mapping types only after publishing WCF server

I have a simple WCF service that is using AutoMapper (6.1.1.0) to map between Entity Framework models and DTO models to transmit down to our client app. We are new to AutoMapper.

We have been working on our development machines with the WCF service running in IIS Express locally and today I published the WCF service to an online server and configured it all up. I can attach to the WCF SVC using the WCF Test Client and can get responses from methods available. Some of these methods use AutoMapper and others don't.

When I got to the 'main' function and tried to get a response I get the 'Error mapping types' error on one of the properties which is one of the DTO classes.

This is the parent class

[DataContract]
public class AgencyDetailDTO
{
    public AgencyDetailDTO()
    {
        credentials = new CredentialsDTO();
        son_blacklist = new List<SONBlacklistDTO>();
    }

    [DataMember]
    public int id { get; set; }

    [DataMember]
    public string pcc { get; set; }

    [DataMember]
    public string name { get; set; }

    [DataMember]
    public string gds { get; set; }

    [DataMember]
    public string default_currency { get; set; }

    [DataMember]
    public bool test { get; set; }

    [DataMember]
    public CredentialsDTO credentials { get; set; }

    [DataMember]
    public List<SONBlacklistDTO> son_blacklist { get; set; }
}

The error I get is

Error mapping types.

Mapping types:
agency_detail -> AgencyDetailDTO
ConfigWCFSA.agency_detail -> 
ConfigSharedModels.AgencyDetailDTO

Type Map configuration:
agency_detail -> AgencyDetailDTO
ConfigWCFSA.agency_detail -> 
ConfigSharedModels.AgencyDetailDTO

Property:
credentials

The 'credentials' is just made up of

[DataContract]
public class CredentialsDTO
{
    [DataMember]
    public int agency_id { get; set; }

    [DataMember]
    public string cf_username { get; set; }

    [DataMember]
    public string cf_password { get; set; }

    [DataMember]
    public string cf_agent_id { get; set; }

    [DataMember]
    public string cf_booker_id { get; set; }
}

so nothing overly difficult, and if I tell AutoMapper to ignore the property it has no problem mapping all the other properties (there are many more Lists that I have left off the 'AgencyDetailDTO' class above to save space).

Like I say this all works perfectly on my development machine - it is just now its on a web server (Win Svr 2012 IIS 8) that we get this mapping issue.

I have created a Mapper config between all the various classes (and all the property names in the EF Models match those in my DTO, and I have used ReverseMap() where required so pretty sure I have all that correct

var config = new MapperConfiguration(cfg => 
        {

            cfg.CreateMap<credentials, CredentialsDTO>().ReverseMap();                
            cfg.CreateMap<agency_detail, AgencyDetailDTO>().ReverseMap();
        });

Any ideas on what could be the root cause ?

Cheers Paul

this is the full error from the WCF service (sorry for that)

Error mapping types.

Mapping types:
agency_detail -> AgencyDetailDTO
ConfigWCFSA.agency_detail -> 
ConfigSharedModels.AgencyDetailDTO

Type Map configuration:
agency_detail -> AgencyDetailDTO
ConfigWCFSA.agency_detail -> 
ConfigSharedModels.AgencyDetailDTO

Property:
credentials

Server stack trace: 
   at
System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood
(Message reply, MessageFault fault, String action, MessageVersion 
version, FaultConverter faultConverter)
   at 
System.ServiceModel.Channels.ServiceChannel.HandleReply
(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at 
System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at 
System.ServiceModel.Channels.ServiceChannelProxy.InvokeService
(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at 
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage
(IMessage reqMsg, IMessage retMsg)
   at 
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke
(MessageData& msgData, Int32 type)
   at IConfigService.GetAgencyConfiguration(String pcc, String gds)
   at ConfigServiceClient.GetAgencyConfiguration(String pcc, String gds)

as requested here is the EF generated agency_detail class

public partial class agency_detail
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public agency_detail()
    {
        this.son_blacklist = new HashSet<son_blacklist>();
    }

    public int id { get; set; }
    public string pcc { get; set; }
    public string name { get; set; }
    public string gds { get; set; }
    public string default_currency { get; set; }
    public bool test { get; set; }

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<son_blacklist> son_blacklist { get; set; }

    public virtual credentials credentials { get; set; }
}

The problem is with CredentialsDTO and a difference between the dev and the prod machine.

Start With which dll contains CredentialsDTO, problem could be:

  • It is in it's own dll, and there is a problem With Access to this dll, or there is an old Version of this dll on the prod server
  • The prod machine has a copy of CredentialsDTO in the GAC that is different from latest version

I would start With renaming CredentialsDTO and credentials and then redeploy.

Finally after several hours debugging this we found the answer ! The database had two columns switched on for 'always encrypted' on the credentials table - however the live server didn't have the correct key to decrypt them (as it was created on a different machine).

So the problem wasn't with AutoMapper it was 'further up the stack' and after attaching some remote debuggers we finally managed to work our way back to the original culprit.

Thanks all for your suggestions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM