Bug 60245 - FieldInfo.GetValue fails on ContextBoundObject
Summary: FieldInfo.GetValue fails on ContextBoundObject
Status: RESOLVED FIXED
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
URL:
Depends on:
Blocks:
 
Reported: 2017-10-18 00:20 UTC by Peter Figuli
Modified: 2017-11-09 15:43 UTC (History)
2 users (show)

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


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

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

Notice (2018-05-21): bugzilla.xamarin.com will be switching to read-only mode on Thursday, 2018-05-25 22:00 UTC.

Please join us on Visual Studio Developer Community and GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs and copy them to the new locations as needed for follow-up. The See Also field on each Bugzilla bug will be updated with a link to its new location when applicable.

After Bugzilla is read-only, if you have new information to add for a bug that does not yet have a matching issue on Developer Community or GitHub, you can create a follow-up issue in the new location. Copy and paste the title and description from this bug, and then add your new details. You can get a pre-formatted version of the title and description here:

In special cases you might also want the comments:

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

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