The dictionary <struct, int> is not ordered properly
I have a WCF service and am trying to send Dictionary<CustomStruct, int>from my client to my server. My WCF service uses a standard base binding.
When I send the dictionary to the server, an error does not occur. But when I try to focus on my dictionary, it is empty.
Strange, what Dictionary<string, string>really works ?!
Does anyone have an idea why mine is Dictionary<CustomStruct, int>empty after it passes through the wire and why it works Dictionary<string, string>.
[EDIT] This is what my structure looks like:
[DataContract]
public struct CustomStruct : IEquatable<CustomStruct>
{
[DataMember]
private string _prop;
public string Prop { get { return _prop; } }
public override int GetHashCode()
{
return Prop.GetHashCode();
}
public static bool operator ==(CustomStruct left, CustomStruct right)
{
...
}
public static bool operator !=(CustomStruct left, CustomStruct right)
{
...
}
public override bool Equals(object obj)
{
...
}
}
+3
2 answers
Here is a working example that does what you want
http://rocksolidknowledge.blob.core.windows.net/demos/CustomStructSerialization.zip
, , , , , - CustomStruct , ,
+1