Share via


InternalsVisibleToAttribute Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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

Inheritance Hierarchy

System. . :: . .Object
  System. . :: . .Attribute
    System.Runtime.CompilerServices..::..InternalsVisibleToAttribute

Namespace:  System.Runtime.CompilerServices
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple := True, Inherited := False)> _
Public NotInheritable Class InternalsVisibleToAttribute _
    Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
public sealed class InternalsVisibleToAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Assembly, AllowMultiple = true, Inherited = false)]
public ref class InternalsVisibleToAttribute sealed : public Attribute
[<Sealed>]
[<AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)>]
type InternalsVisibleToAttribute =  
    class
        inherit Attribute
    end
public final class InternalsVisibleToAttribute extends Attribute

The InternalsVisibleToAttribute type exposes the following members.

Constructors

  Name Description
Public method InternalsVisibleToAttribute Initializes a new instance of the InternalsVisibleToAttribute class with the name of the specified friend assembly.

Top

Properties

  Name Description
Public property 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.

Top

Methods

  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

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 InternalsVisibleToAttribute 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.

They can also appear with separate InternalsVisibleToAttribute tags but a single assembly keyword.

The friend assembly is identified by the InternalsVisibleToAttribute 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 InternalsVisibleToAttribute constructor must include the full public key as well as the name of the assembly. For more information about using InternalsVisibleToAttribute with strong-named assemblies, see the InternalsVisibleToAttribute constructor.

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.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

System.Runtime.CompilerServices Namespace