Bug 54388 - InternalsVisibleTo is case sensitive
Summary: InternalsVisibleTo is case sensitive
Alias: None
Product: Runtime
Classification: Mono
Component: JIT (show other bugs)
Version: master
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Katelyn Gadd
Depends on:
Reported: 2017-04-02 13:16 UTC by softlion
Modified: 2017-09-06 15:08 UTC (History)
5 users (show)

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


Description softlion 2017-04-02 13:16:39 UTC
The assembly name set as InternalsVisibleTo parameter is case insensitive.

[assembly: InternalsVisibleTo("MyControlForms.Ios")]

If the assembly name is set to MyControlForms.iOS, the compiler compiles fine (it authorize the use of any internal property), but accessing any internal property crashes at runtime with

	Unhandled Exception:
	System.FieldAccessException: Field `MyControlForms:MyInternalProperty' is inaccessible from method `MyControlForms.iOS.MyControlRenderer...

It should not crash, or the compiler should fail to compile.
Comment 1 Katelyn Gadd 2017-04-03 21:34:23 UTC
In Xamarin Studio 6.2.1 build 3, if the case of the assembly name does not match, I get a build failure saying that the member is inaccessible due to its protection level. If I correct the case of the assembly name the test application builds.

Can you provide a more specific example of some code (or ideally a pair of projects) where this failure occurs? I can't reproduce it.
Comment 2 Marek Safar 2017-04-03 22:20:28 UTC
Katelyn, I think that's the bug. The runtime loader treats the InternalsVisibleTo value as case sensitive which probably shouldn't (requires checking on .net)
Comment 3 Katelyn Gadd 2017-04-03 22:21:27 UTC
So the intended behavior is not "It should not crash, or the compiler should fail to compile." but "it should work"? I'll see how this works on Windows.
Comment 4 softlion 2017-04-04 04:50:58 UTC
I'm on vs2015 windows not xs.
Don't know what the c# spec directs here.
Comment 5 Katelyn Gadd 2017-04-04 20:42:26 UTC
OK, I can confirm that in VS2015 on windows, the case of the argument to InternalsVisibleTo is ignored. It still fails as expected if the name is entirely incorrect. I assume this is done to make sure things still work if win32 case insensitivity causes the assembly name to get messed up.

So to match this behavior, I think the mono runtime would need to change, in addition to the mono compiler.
Comment 6 Katelyn Gadd 2017-04-06 18:02:33 UTC
@softlion What version of Xamarin.iOS are you using?
Comment 7 softlion 2017-04-06 18:03:28 UTC
I was using the beta version which is the stable version since a couple of days.
Comment 8 Katelyn Gadd 2017-04-06 18:05:01 UTC
OK, 15.1? Thanks. I'll chase this down.

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