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)

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


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

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.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

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