0

I am using the NetDataContractSerialiser with WCF. This is working well with all our types being serialised. However, a service I am calling is generating the following exception

The formatter threw an exception while trying to deserialize the message:

There was an error while trying to deserialize parameter http://tempuri.org/:xmlServiceObjIN. The InnerException message was 'The deserializer cannot load the type to deserialize because type 'System.Collections.Generic.EnumEqualityComparer`1[[GrantEd.Common.DomainModel.Code.Enums.enumFundingParameterContextKey, GrantEd.Common.DomainModel.Code, Version=14.0.71.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 class being serialised has a property defined as

public IDictionary<enumFundingParameterContextKey, string>  Context { get; set; }

the declaration of the enum is

[Serializable]
public enum enumFundingParameterContextKey
{
    [EnumMemberAttribute()]
    ClientId = 0,
    [EnumMemberAttribute()]
    EntitlementDefinitionId = 1
}

which is defined in another assmebly.

When I replace the enumeration with int the class deserialises with no problems. Any ideas why using the enum would result the exception?

The reason for using NetDataContractSerializer was to for type information to be available and avoid having to use KnownType

tshepang
  • 12,111
  • 21
  • 91
  • 136
Peter
  • 1

2 Answers2

1

Make the base type as non integer for your enum. e.g. a byte.

Example:

[Serializable] public enum enumFundingParameterContextKey : byte
{
    [EnumMemberAttribute()]
    ClientId = 0,
    [EnumMemberAttribute()]
    EntitlementDefinitionId = 1
}

Details are in my following blog post: dotnet-35-to-dotnet-40-enum

James Allardice
  • 164,175
  • 21
  • 332
  • 312
Kajal Sinha
  • 1,565
  • 11
  • 20
0

Try to mark enum with [DataContract] instead of [Serializable]. But it looks like the enum type is unknown at all on the client.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • sadly no luck after changing to use DataContract. Verified also correct assembly on client. – Peter Jun 03 '11 at 01:39