wcf netdatacontractserializer exception serialising idictionary with enumeration as key

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

Answers


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


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


Need Your Help

c# execute large SQL statement

c# sql oracle

I have a large SQL statement that I'd like to run in c#, however, all the examples I've seen are for SQL statements that are one line in length.

<a> tag inside <li> padding transition moves the list on hovering the first element

html css css3 flexbox

I'm trying to do a list with a padding-left transition on hovering the tag inside the &lt;li&gt; tag, as you can see in the following fiddle: