Bug 249 - .Net 4.0-compiled application using .Net 3.5-compiled library for DataContractSerializer fails
Summary: .Net 4.0-compiled application using .Net 3.5-compiled library for DataContrac...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies (show other bugs)
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-08-09 16:50 UTC by Brandon Wallace
Modified: 2011-08-25 03:15 UTC (History)
2 users (show)

See Also:
Tags: DataContractSerializer
Is this bug a regression?: ---
Last known good build:

VS2010 Projects and source (6.60 KB, application/x-zip-compressed)
2011-08-09 16:50 UTC, Brandon Wallace

Description Brandon Wallace 2011-08-09 16:50:06 UTC
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
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            Included Boehm (with typed GC and Parallel Mark)
Comment 1 Zoltan Varga 2011-08-24 20:13:25 UTC
-> class libs.

Note You need to log in before you can comment on or make changes to this bug.