Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of internal FriendAccessAllowedAttribute in WPF

Tags:

.net

wpf

During a run through Reflector to find the root cause of a bug in a WPF application, I stumbled across an internal attribute FriendAccessAllowedAttribute that is littered across many different classes, members, etc. However, I'm unable to locate what exactly uses this attribute (if anything). My guess is this is part of the C++/CLI infrastructure, but a search of MSDN, the C++/CLI spec, and the CLI spec reveals nothing. Is anybody aware of what it is used for?

like image 749
user7116 Avatar asked Oct 08 '09 21:10

user7116


2 Answers

As I recall, it was a way to control dependencies between friend assemblies in the Framework. Basically, when you grant assembly A "friend" access to assembly B, you don't want all internal members of B to be made available to A, because then any change to such a member would potentially be breaking (also, it would increase the security surface area that needs to be reviewed). Pretty sure this attribute is honored in Silverlight, not sure about the full Framework.

like image 86
Eugene Osovetsky Avatar answered Nov 09 '22 11:11

Eugene Osovetsky


Interestingly, that attribute is attributed with itself!

Decompiled from C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll, version 4.0:

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum |
                AttributeTargets.Constructor | AttributeTargets.Method |
                AttributeTargets.Property | AttributeTargets.Field |
                AttributeTargets.Event | AttributeTargets.Interface, 
                AllowMultiple = false, Inherited = false)]
[FriendAccessAllowed]
internal sealed class FriendAccessAllowedAttribute : Attribute
{
}

So I presume it can only be used by selected assemblies which are assigned friends of mscorlib.


EDIT Microsoft's reference source for the attribute shows the definition is alongside InternalsVisibleToAttribute and includes the comment string:

If AllInternalsVisible is not true for a friend assembly, the FriendAccessAllowed attribute indicates which internals are shared with that friend assembly.

like image 30
Drew Noakes Avatar answered Nov 09 '22 10:11

Drew Noakes