DataContract Serialization Error with NHibernate 1.2 class lazy="true"

Hi

We moved our application to NHibernat 1.2 GA from NHibernate 1.0.3.

If I declare our class definition in the mapping file by setting lazy="true", I am getting an exception that is raising Communication Exception

There was an error while trying to serialize parameterhttp://tempuri.org/:ExecuteServiceResult. The InnerException message was 'Type 'CProxyTypeDomainLocalAgencyEntityDomain_NHibernate_ProxyINHibernateProxy1' with data contract name 'CProxyTypeDomainLocalAgencyEntityDomain_NHibernate_ProxyINHibernateProxy1:http://schemas.datacontract.org/2004/07/' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'.

Here is the corresponding class declaration in the mapping file.

<class name="Domain.LocalAgencyEntity, DataAccess" table="Zipcode" lazy="true" select-before-update="true">
..........
</class>

If I change that to

<class name="Domain.LocalAgencyEntity, DataAccess" table="Zipcode" lazy="false" select-before-update="true">
..........
</class>

it is working fine. Unfortunately lazy="true" is required by the architecture. Could anyone please help me in fixing this issue. I am running out of options.

Thanks

--Rama.NET--

[2096 byte] By [Rama.NET] at [2008-1-8]
# 1

Hi Rama,

It seems that when lazy loading for NHibernate is enabled, NHibernate generates a dynamic proxy (CProxyTypeDomainLocalAgencyEntityDomain_NHibernate_ProxyINHibernateProxy1) for your class (Domain.LocalAgencyEntity), which I believe you preivously added it to your knownType.

Since your known type has changed once lazy loading is enabled, you ran into the above exception . The solution is to add the new proxy type to the known type. If you don't know about the type name/definition ahead of time, you can provide a method to the ServiceKnownType attribute like the following:

[ServiceKnownType("MethodReturningGeneratingType")]

where MethodReturningGeneratingType should have the following signature:

Type[] MethodReturningGeneratingType(ICustomAttributeProvider provider) { /* return all your generated types */}

Hope this helps.

Thanks,

Sara

SaraWong-MSFT at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 2

Sara

Thanks for replying. I will try add the new proxy type to the list of known types like you mentioned.

Thanks

Rama

(Currently breathing .NET)

Rama.NET at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...

Visual Studio Orcas

Site Classified