Created attachment 102 [details]
VS2010 Projects and source
Here is the scenario:
SerializeLib.dll is compiled against .NET 3.5 Framework. It provides 2 methods:
string Serialize(object data) // uses DataContractSerializer to serialize to xml
object Deserialize(string xml, Type t) // uses DataContractSerializer to deserialize from xml.
Program.exe is compiled against .NET 4.0 Framework.
It creates a simple class where it uses [IgnoreDataMember] attribute to mark certain properties for exclusion when serialized.
It has another class which has the [DataContract] attribute. This class is missing the [DataMember] attribute from one of its properties so that the property will be excluded.
The [IgnoreDataMember] attribute is not honored and the properties with this attribute are serialized when they should not be when I use the methods defined in SerializeLib.dll to perform the work.
And the class with the [DataContract] serializes all properties even those missing the [DataMember] attribute.
If I recompile SeralizeLib.dll using the .NET Framework 4.0, then the problem goes away.
Microsoft's .NET runtime does not have this issue. The program works correctly if SerializeLib.dll is compiled against 3.5 or 4.0.
You can use the attached VS2010 projects to compile the bits, or you can compile them on mono with:
gmcs -out:SerializeLib.dll -target:library -r:System.Runtime.Serialization MyXmlSerializer.cs
dmcs -out:Program.exe Program.cs -r:SerializeLib.dll,System.Runtime.Serialization
mono --runtime=v4.0.30319 Program.exe
This will produce exceptions when the program sees that the deserialized object has values for the properties in question.
Recompiling SerializeLib.dll with "dmcs" so that it targets .NET 4.0 and then rerun Program.exe and everything works without error.
mono -- version:
Mono JIT compiler version 2.10.3 (tarball Mon Aug 8 13:48:37 CDT 2011)
Copyright (C) 2002-2011 Novell, Inc and Contributors. www.mono-project.com
LLVM: supported, not enabled.
GC: Included Boehm (with typed GC and Parallel Mark)
-> class libs.