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 ()
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)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 249 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

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.