Updated: May 2011
Specifies that types that are ordinarily visible only within the current assembly are visible to a specified assembly.
Assembly: mscorlib (in mscorlib.dll)
Thetype exposes the following members.
|AllInternalsVisible||Infrastructure. This property is not implemented.|
|AssemblyName||Gets the name of the friend assembly to which all types and type members that are marked with the internal keyword are to be made visible.|
|TypeId||When implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)|
|Equals||Infrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetHashCode||Returns the hash code for this instance. (Inherited from Attribute.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|IsDefaultAttribute||When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)|
|Match||When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
|_Attribute.GetIDsOfNames||Maps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)|
|_Attribute.GetTypeInfo||Retrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)|
|_Attribute.GetTypeInfoCount||Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)|
|_Attribute.Invoke||Provides access to properties and methods exposed by an object. (Inherited from Attribute.)|
Ordinarily, types and members with internal scope (in C#) and friend scope (in Visual Basic) are visible only in the assembly in which they are defined. The attribute makes them also visible to the types in a specified assembly, which is known as a friend assembly.
The attribute is applied at the assembly level. This means that it can be included at the beginning of a source code file, or it can be included in the AssemblyInfo file in a Visual Studio project. You can use the attribute to specify a single friend assembly that can access the internal types and members of the current assembly. You can define multiple friend assemblies in two ways. They can appear as individual assembly-level attributes, as the following example illustrates.
They can also appear with separate tags but a single assembly keyword, as the following example illustrates.
The friend assembly is identified by the InternalsVisibleToAttribute constructor. Both the current assembly and the friend assembly must be unsigned, or both must be signed with a strong name. If they are signed with a strong name, the argument to the InternalsVisibleToAttribute constructor must include the full public key as well as the name of the assembly. For more information about using with strong-named assemblies, see the InternalsVisibleToAttribute constructor.
Do not include values for the CultureInfo, Version, or ProcessorArchitecture fields in the argument to the constructor; the Visual Basic, C#, and C++ compilers treat this as a compiler error. If you use a compiler that does not treat it as an error (such as the Ilasm.exe (MSIL Assembler)) and the assemblies are strong-named, a MethodAccessException is thrown the first time the specified friend assembly accesses the assembly that contains the attribute.
If you use the C# compiler to compile the friend assembly, you must explicitly specify the name of the output file (.exe or .dll) by using the /out compiler option. This is required because the compiler has not yet generated the name for the assembly it is building at the time it is binding to external references. The /out compiler option is optional for the Visual Basic compiler, and the corresponding --out or –o compiler option should not be used when compiling friend assemblies with the F# compiler.
For more information about how to use this attribute, see the following topics:
The following example defines a FileUtilities class that includes an internal AppendDirectorySeparator method. The attribute is applied to the assembly that contains the FileUtilities class. The attribute allows an assembly named Friend1 to access this internal member.
If the following example is compiled into a strong-named assembly named Friend1, the Example.Main method in Friend1 can successfully call the FileUtilities.AppendDirectorySeparator method, even though the method is internal to the Assembly1 assembly.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.