Bug 319019 (MONO76136) - [GMCS] Getting a generic struct via reflection fails
Summary: [GMCS] Getting a generic struct via reflection fails
Status: RESOLVED FIXED
Alias: MONO76136
Product: Mono: Runtime
Classification: Mono
Component: misc (show other bugs)
Version: 1.0
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Martin Baulig
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-17 16:13 UTC by Steffen Kieß
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 19:31:03 UTC


---- Reported by kiess@h3c.de 2005-09-17 09:13:57 MST ----

Description of Problem:
When reading a generic struct with System.Reflection.FieldInfo.GetValue the
returned value is wrong.

Steps to reproduce the problem:
1. cat > test.cs << EOF
public struct Container<T> {
  public T content;
  
  public Container (T content) {
    this.content = content;
  }
}

public class A {
  public Container<int> field;
  
  public A () {
    field = new Container<int> (1);
  }
}

public class M {
  public static void Main() {
    A a = new A();

    System.Console.WriteLine (a.field.content);

    object o = a.GetType().GetField("field").GetValue (a);
    Container<int> unboxed = (Container<int>)o;
    System.Console.WriteLine (unboxed.content);
  }
}
EOF
2. gmcs test.cs
3. mono test.exe

Actual Results:
1
0

Expected Results:
1
1

How often does this happen? 
always

Additional Information:



---- Additional Comments From vargaz@gmail.com 2005-11-15 09:23:44 MST ----

For the record:

This is caused by the fact that mono_type_get_underlying_type () returns
a MonoType for GENERICINST types whose data.klass field points to
the 'generic' generic class, not the 'specific' generic class created
by mono_class_create_generic (). So either
mono_type_get_underlying_type () needs to return the 'specific'
generic class (and the byval_arg
field of this class needs to point to itself and not to the generic
class), or the code calling get_underlying_type () needs to call
mono_class_from_mono_type () instead of accessing type->data.klass
directly. There are lots of places inside the runtime where this
bug manifests itself. For example, 

https://bugzilla.novell.com/show_bug.cgi?id=MONO75479

is caused by the same problem.






---- Additional Comments From martin@ximian.com 2005-11-15 13:53:48 MST ----

Fixed in SVN.



---- Additional Comments From martin@ximian.com 2005-11-15 14:01:45 MST ----

.

This bug blocked bug(s) 75735.

Unknown operating system unknown. Setting to default OS "Other".