Bug 31969 - Add support for DisablePrivateReflectionAttribute
Summary: Add support for DisablePrivateReflectionAttribute
Status: CONFIRMED
Alias: None
Product: Runtime
Classification: Mono
Component: Reflection (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Aleksey Kliger
URL:
Depends on:
Blocks:
 
Reported: 2015-07-15 10:26 UTC by Marek Safar
Modified: 2015-10-20 18:00 UTC (History)
2 users (show)

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


Attachments
Example using DisablePrivateReflectionAttribute (6.62 KB, application/zip)
2015-10-16 14:32 UTC, Aleksey Kliger
Details
DisablePrivateReflection example (3.37 KB, application/octet-stream)
2015-10-20 18:00 UTC, Aleksey Kliger
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 for Bug 31969 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Comment 1 Aleksey Kliger 2015-10-16 14:32:58 UTC
Created attachment 13385 [details]
Example using DisablePrivateReflectionAttribute

What's the correct way to use DisablePrivateReflectionAttribute to get it to actually work on .NET?

Tried the attached project in VS2015 and it happily dumped private fields and methods.  Tried both reflecting on the current assmebly, on a loaded one, and on a dynamic one.
Comment 2 Marek Safar 2015-10-16 14:38:39 UTC
Did you try it not within same assembly?
Comment 3 Aleksey Kliger 2015-10-16 14:43:43 UTC
Yes.  Attached project has two assemblies.  Bug31369 has some classes and has the DisablePrivateReflection attribute.   ReproRuntime is a separate assembly that  calls Assembly.Load() to bring in Bug31369 and then dumps all the fields and methods from one of its classes.  You get everything.

(Tried it both in Debug and Release modes in VS and checked that I was using .NET 4.6).

I guess the one experiment I haven't tried is not using the reflection API to bring in the second assembly, but just using it directly in the main project.
Comment 4 Marek Safar 2015-10-20 07:40:44 UTC
It looks like it's somehow related to IVT attribute

https://github.com/dotnet/coreclr/blob/master/src/vm/assembly.cpp#L2161
Comment 5 Aleksey Kliger 2015-10-20 10:11:03 UTC
Thanks, that looks promising. I'll try to cook up a testcase.
Comment 6 Aleksey Kliger 2015-10-20 16:00:06 UTC
My mistake.  Just enumerating the names of class methods and members doesn't trigger access restrictions.  You have to actually try to call them.
Comment 7 Aleksey Kliger 2015-10-20 18:00:29 UTC
Created attachment 13466 [details]
DisablePrivateReflection example

Okay, I've got a working example.

Reproduction steps:

mcs dprExample.cs
mono dprExample.exe

Expected output:
{{ MethodAccessException thrown when trying to invoke hello_private }}

Actual output:
 - hello_public;
  attempting to invoke hello_public.
  invoked hello_public
 - hello_private;
  attempting to invoke hello_private.
  invoked hello_private