Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when using AutoMapper to map from a POCO to an NHibernate proxy object

We recently upgraded AutoMapper and ran into an issue when mapping items a certain way.

When I load an NHibernate domain object, and attempt to map my model to it in the following manner:

var myPoco = new MyPoco();
var proxy = repository.Load<MyDomainObject>(id);
Mapper.Map(myPoco, proxy);

I get the following error:

Missing type map configuration or unsupported mapping.

MyPoco-> MyDomainObjectProxy

However, if I use the following overload of the method, I do not get the exception:

var myDomainObj = Mapper.Map<MyPoco, MyDomainObject>(myPoco);

When you look into the AutoMapper code, you can see that these methods call different base methods in the code base, which is why they behave differently.

Is this a bug with the newer version of AutoMapper, or is there another way of using the Mapper.Map(source, destination) method with proxies?

Note: this is using AutoMapper 2.2.0. I believe this worked fine in 0.3.

like image 425
Erik Avatar asked Oct 01 '12 15:10

Erik


1 Answers

This is a known issue, fixed the develop branch. Check out the prerelease version here:

AutoMapper 2.2.1-ci8

The fix will be released shortly in the 2.2.1 version.

like image 161
Jimmy Bogard Avatar answered Sep 27 '22 19:09

Jimmy Bogard