Bug 60245 - FieldInfo.GetValue fails on ContextBoundObject
Summary: FieldInfo.GetValue fails on ContextBoundObject
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 5.0 (2017-02)
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Aleksey Kliger
Depends on:
Reported: 2017-10-18 00:20 UTC by Peter Figuli
Modified: 2017-11-09 15:43 UTC (History)
2 users (show)

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

Simple test case source file (639 bytes, text/plain)
2017-10-18 00:20 UTC, Peter Figuli

Description Peter Figuli 2017-10-18 00:20:39 UTC
Created attachment 25348 [details]
Simple test case source file

FieldInfo.GetValue() fails to return correct reference.

Results Mono/Linux:

Field:"IntField" is type of:System.Int32
Field:"StringField" is type of:TestNamespace.TestClass

Results .NET/Windows

Field:"IntField" is type of:System.Int32
Field:"StringField" is type of:System.String
Comment 1 Aleksey Kliger 2017-10-24 19:28:34 UTC
Can reproduce this on mono master.
Comment 2 Aleksey Kliger 2017-10-24 20:09:27 UTC
We end up in a call in `mono_field_get_value_object_checked (domain, field, obj, error)` with obj a TransparentProxy.  After that we call `mono_field_get_value (obj, field, &o)` which is essentially a memcpy from some random offset inside the transparent proxy.

We instead need a call to `mono_load_remote_field_new_checked`.

A few more observations:
 1. It doesn't do anything sensible with the valuetype field either, it just so happens that the valuetype codepath boxes up whatever bits happen to be there into a boxed integer - the boxing code doesn't care that the value is junk, it'll still be a System.Int32
 2. If you add a few more reference fields you can get some null pointer exceptions because the object layout of a transparent proxy has a couple of null fields later on.
 3. The setter code is likely broken too.
Comment 3 Aleksey Kliger 2017-11-08 17:49:55 UTC
This reproduces with mono versions back to at least 4.6.2

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