Wcf – using NetDataContractSerializer throws an exception on client side

wcf

I've tried to move WCF to NetDataContractSerializer using the code in this post:
http://lunaverse.wordpress.com/2007/05/09/remoting-using-wcf-and-nhibernate

and adding this code on the client side:

    foreach (OperationDescription desc in factory.Endpoint.Contract.Operations)
    {
        DataContractSerializerOperationBehavior dcsOperationBehavior = desc.Behaviors.Find<DataContractSerializerOperationBehavior>();
        if (dcsOperationBehavior != null)
        {
            int idx = desc.Behaviors.IndexOf(dcsOperationBehavior);
            desc.Behaviors.Remove(dcsOperationBehavior);
            desc.Behaviors.Insert(idx, new NetDataContractOperationBehavior(desc));
            //return true;

        }               
    }

But Eevry time I ivoke my List call, I get this exception:

the formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:ListResult. The InnerException message was 'The deserializer cannot load the type to deserialize because type 'System.Collections.Generic.List`1[[MYPROJ.Framework.Entities.EntityBase, MYPROJ.Framework.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' could not be found in assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Check that the type being serialized has the same contract as the type being deserialized and the same assembly is used.'. Please see InnerException for more details.

The InnerExcption:

The deserializer cannot load the type to deserialize because type 'System.Collections.Generic.List`1[[MYPROJ.Framework.Entities.EntityBase, MYPROJ.Framework.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' could not be found in assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Check that the type being serialized has the same contract as the type being deserialized and the same assembly is used.

The Proxy is generated using svcutils with this flag: /ct:System.Collections.Generic.List`1
so the lists on the other side will not turn into arrays.

The type that the deseriliezer looking is defined in the server. all the entities are derived from this type, but this is not the namespace of the proxy which resides in the client side.

Using Regular default serializer for WCF works fine (there are other problems involving dealing with circular reference the cause me to try a different serializer).
Any Ideas ?

Thanks,
Dani

Best Answer

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/433ba785-581c-4dfa-861a-f22574c1b463

This article says NetDataContract Doesn't support svcutil generated proxy, and you must use a shared dll.

Related Topic