Partager via


@ Assembly

Links an assembly to the current page during compilation, making all the assembly's classes and interfaces available for use on the page.

<%@ Assembly Name="assemblyname" %>
<%@ Assembly Src="pathname" %>

Attributes

  • Name
    A string that represents the name of the assembly to link to the page.

    Note   The assembly name does not include a file name extension.

  • Src
    The path to a source file to dynamically compile and link against.

    Note   You cannot include a Name and a Src attribute in the same @ Assembly directive. If you want to use both, you must include more than one directive on the page.

Remarks

The compiler references the assembly at compile time, allowing early binding. Once compilation of the requested page is complete, the assembly is loaded into the application domain, allowing late binding.

Assemblies that reside in your Web application's \bin directory are automatically linked to pages within that application. Such assemblies do not require the @ Assembly directive. You can disable this functionality by removing the following line from the <assembly> section of your application's Web.config file:

<add assembly="*"/>

Note   You cannot include the path to an assembly in an @ Assembly directive.

As an alternative to using the @ Assembly directive, you can use the Web.config file to link assemblies across an entire application. For more information about the Web.config file and configuring your application, see ASP.NET Configuration.

Example

The following code fragment uses two @ Assembly directives, the first to link to MyAssembly, a user-defined assembly, the second to MySource.vb, a Visual Basic .NET source file.

<%@ Assembly Name="MyAssembly" %>
<%@ Assembly Src="MySource.vb" %>

See Also

ASP.NET Web Forms Syntax | Directive Syntax