[Mono-bugs] [Bug 569405] New: Reflection isn't able to change static readonly fields. .NET difference

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Jan 8 16:54:11 EST 2010



           Summary: Reflection isn't able to change static readonly
                    fields.  .NET difference
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 1.2.0
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: tom_hindle at sil.org
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---

User-Agent:       Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;
Trident/4.0; GTB6.3; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR
3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)

I have a field:

private static readonly MyClass s_class = new MyClass(1);

I then do:

var fieldInfo = this.GetType().GetField("s_class", BindingFlags.Static |
            fieldInfo.SetValue(this, new MyClass(2));

On .Net s_class now refs the MyClass(2) instance while on mono it still refs
the MyClass(1).

I know this is horrible thing to do but I thought I would report the differnce.

Attached sample program showing difference.

Reproducible: Always

Steps to Reproduce:
1. Compile and run attached program
Actual Results:  

Expected Results:  

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