This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 8037 - GetCustomAttributes returns wrong results when using NET4 and NET35 assemblies mixed
: GetCustomAttributes returns wrong results when using NET4 and NET35 assemblie...
Status: RESOLVED FIXED
Product: Class Libraries
Classification: Mono
Component: System
: unspecified
: Macintosh Mac OS
: --- normal
: ---
Assigned To: Bugzilla
:
:
:
:
  Show dependency treegraph
 
Reported: 2012-10-28 15:23 EDT by Timo Dörr
Modified: 2012-11-17 08:23 EST (History)
4 users (show)

See Also:
Tags:
Test Case URL:
External Submit: ---


Attachments

Description Timo Dörr 2012-10-28 15:23:14 EDT
When calling typeof(MyClass).GetCustomAttribtutes () the results may be wrong
when MyClass is defined in a NET4 assembly and GetcustomAttributes is called
from withing a NET35 assembly.

I've set up a minimal testcase to reproduce (the source along with .sln/.csproj
is also on github for convenience:
git@github.com:Dynalon/getcustomattributes-bug.git)

Steps to reproduce:

1) Create a new .NET35 library project, add the following source:

using System;
using System.Runtime.Serialization;
using System.Linq;

namespace Sample35Project
{
    public static class Sample35Class
    {
        public static void Print<T> ()
        {
            var isDataContract = typeof(T).GetCustomAttributes
(typeof(DataContractAttribute), false).Any ();
            Console.WriteLine (isDataContract);
        }
    }
}

2) In the same solution, create a new .NET4 cmdline project that references the
previous Sample35Project:

using System;
using System.Runtime.Serialization;
using System.Linq;
using Sample35Project;

namespace Test
{
    [DataContract]
    public class MyClass
    {
        [DataMember (Name = "some-title")]
        string Title { get; set; }
    }

    class MainClass
    {
        public static void Main (string[] args)
        {
            Sample35Class.Print<MyClass> ();
        }
    }
}


3) Run the program. The result will be "False", because isDataContract will
evaluate to false. When running the same binaries on a windows7 machine, the
output is True (which is correct).

Expected: True (isDataContract should evaluate to true).

Other notable behaviour which might help:
4) Switch the cmdline program build target to NET35. Recompile an run the
program, the result will be True (which is correct).
5) Switch the Sample35Project build target to NET4 (so now both are NET4). The
result will be True again (which is correct).

So basically, only if the cmdline program uses NET4 and the other project (that
calls GetCustomAttributes) is NET35, there will be wrong behavior. this does
not happen on a windows7 machine using microsoft's .NET VM.

Tested on Mac OS X Lion with Mono 2.10.9 and 3.0 beta, as well as on an
opensuse 12.1 box using mono 2.10.6 - all affected. This bugs affects
ServiceStack usage with mono, see the issue on their github:
https://github.com/ServiceStack/ServiceStack/issues/307
Comment 1 Marek Safar 2012-11-11 12:50:00 EST
Fixed in master
Comment 2 Andres G. Aragoneses 2012-11-17 08:23:44 EST
*** Bug 6528 has been marked as a duplicate of this bug. ***

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