[Mono-bugs] [Bug 528055] New: Obfuscation of field names of anonymous types causes System.MissingFieldException

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Aug 4 13:00:36 EDT 2009


http://bugzilla.novell.com/show_bug.cgi?id=528055


           Summary: Obfuscation of field names of anonymous types causes
                    System.MissingFieldException
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.4.x
          Platform: x86
        OS/Version: Windows Vista
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: ben at challenor.org
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


Created an attachment (id=310441)
 --> (http://bugzilla.novell.com/attachment.cgi?id=310441)
example (unobfuscated and obfuscated) that exhibits the problem

Apologies if this does not belong in mscorlib.

Description of Problem:
I need to deploy an application on both the Mono and Microsoft runtimes, but
this issue only affects Mono. Our obfuscator is renaming the fields in the
anonymous type, causing a System.MissingFieldException.

Steps to reproduce the problem:
Attaching a simple example (unobfuscated and obfuscated) that exhibits the
problem, with the following source code.

using System;

namespace Example
{
    class Program
    {
        static void Main()
        {
            var x = new { i = 1, b = true };
            Console.WriteLine(x);
        }
    }
}

Actual Results:
D:\Share\Example1\bin\Debug>Example.exe
{ i = 1, b = True }

D:\Share\Example1\bin\Debug>Obfuscated\Example.exe
{ i = 1, b = True }

D:\Share\Example1\bin\Debug>"C:\Program Files\Mono-2.4\bin\mono.exe"
Example.exe

{ i = 1, b = True }

D:\Share\Example1\bin\Debug>"C:\Program Files\Mono-2.4\bin\mono.exe"
Obfuscated\
Example.exe

Unhandled Exception: System.MissingFieldException: Field
'.<>f__AnonymousType0`2
a' not found.
  at a.a () [0x00000]

Expected Results:
As per the Microsoft output above.

How often does this happen? 
Always.

Additional information:
Initially I thought this might be because the obfuscator overloads the fields
on return type only (so they both become 'a'). This is supported in IL, but not
C#. However, the following example does NOT exhibit the problem (even though
both fields are called 'a' after obfuscation). Thus I think it might be
restricted to anonymous types.

using System;

namespace Example
{
    class Program
    {
        private static int i;
        private static bool b;

        static void Main()
        {
            i = 1;
            b = true;

            Console.WriteLine(i);
            Console.WriteLine(b);
        }
    }
}

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list