mscorlib 2.0.0.0 4.0.0.0 System.Attribute System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=true, Inherited=false)

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.

code reference: System.Runtime.CompilerServices.InternalsVisibleToAttribute#3

They can also appear with separate tags but a single assembly keyword, as the following example illustrates.

code reference: System.Runtime.CompilerServices.InternalsVisibleToAttribute#4

The friend assembly is identified by the constructor. Both the current assembly and the friend assembly must be unsigned, or both assemblies must be signed with a strong name. If they are signed with a strong name, the argument to the 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 constructor.

Do not include values for the , , or field in the argument; 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 MSIL Assembler (ILAsm.exe)) and the assemblies are strong-named, a exception 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:

Friend Assemblies (C++)

Friend Assemblies (C# and Visual Basic)

Specifies that types that are ordinarily visible only within the current assembly are visible to a specified assembly.

- Constructor
  2.0.0.0
  4.0.0.0

  The constructor defines a friend assembly, which is an assembly that has access to the internal types and members of the current assembly.

  Both the current assembly and the friend assembly must be unsigned, or both must be signed with a strong name. (For more information about strong-named assemblies, see Creating and Using Strong-Named Assemblies.) If both are unsigned, the parameter consists of the name of the friend assembly, specified without a directory path or file extension. If both are signed, consists of the name of the friend assembly along with its full public key (but not its public key token). The other components of a strong name, such as those that provide culture, version, or processor architecture information, cannot be specified in the parameter.

  You can use Sn.exe (Strong Name Tool) to retrieve the full public key from a strong-named key (.snk) file. To do this, you perform the following steps:

  Extract the public key from the strong-named key file to a separate file:

  Sn -p snk_file outfile

  Display the full public key to the console:

  Sn -tp outfile

  Copy and paste the full public key value into your source code.

  For more information about how to use the attribute, see the following topics:

  Friend Assemblies (C++)

  Friend Assemblies (C# Programmer's Reference)

  Initializes a new instance of the class with the name of the specified friend assembly.

  The name of a friend assembly.
- Property
  2.0.0.0
  4.0.0.0
  System.Boolean To be added. To be added.

  This property is not implemented.

- Property
  2.0.0.0
  4.0.0.0
  System.String To be added.

  For more information about how to use the attribute, see the following topics:

  Friend Assemblies (C++)

  Friend Assemblies (C# Programmer's Reference)

  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.