Bug 6528 - DataContract attribute usage with empty string doesn't have any effect
Summary: DataContract attribute usage with empty string doesn't have any effect
Status: RESOLVED DUPLICATE of bug 8037
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-08-14 12:14 UTC by Andres G. Aragoneses
Modified: 2012-11-17 08:23 UTC (History)
4 users (show)

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


Attachments
test case (152.24 KB, application/x-bzip)
2012-08-14 12:14 UTC, Andres G. Aragoneses
Details

Description Andres G. Aragoneses 2012-08-14 12:14:29 UTC
Created attachment 2344 [details]
test case

When using DataContractSerializer sometimes the XML tags outputted may contain "d2p1" namespaces.

To workaround this problem in theory the attribute [DataContract(Namespace = "")] can be used in the class.

This works in MS.NET but not on Mono.

Attaching testcase (just build with xbuild* and run with nunit-console, which in my system defaults to 2.6.0.0 in the 4.0 runtime).

*Or use the DLLs provided in the compressed attachment inside bin/Debug.

Current results: 1 test fails, 2 pass
Expected results (MS.NET): 3 tests pass
Comment 1 Andres G. Aragoneses 2012-10-07 20:03:53 UTC
So it turns out the bug is not actually inside the class libraries:

My testcase contains 2 assemblies; one of them is compiled with TargetFramework=3.5 and the other 4.0. As soon as you change them (their .csprojs) to use the same version of the framework (both 3.5 or both 3.5), the bug disappears.

And this happens because the class that contains the [DataContract] attribute targets framework 4.0, but the call to the ctor of DataContractSerializer happens in the assembly that references framework 3.5, then the call for Type.GetCustomAttributes(T) fails because T is typeof(DataContractAttribute), v3.0.0.0, not 4.0.0.0.

But Microsoft.NET doesn't have this bug even in machines with more than one version of the runtime.

I think I'll post an email in the mono-devel mailing list about this interesting finding.
Comment 2 Andres G. Aragoneses 2012-10-07 20:10:05 UTC
typo: s/both 3.5 or both 3.5/both 3.5 or both 4.0/

BTW I posted about this in mono-devel: http://lists.ximian.com/pipermail/mono-devel-list/2012-October/039675.html
Comment 3 Andres G. Aragoneses 2012-11-17 08:23:44 UTC
The fix for #8037 fixes this as well, so it is effectively the same bug.

*** This bug has been marked as a duplicate of bug 8037 ***

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