Expand Minimize

AppDomain.DefineDynamicAssembly Method (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)

Note: This API is now obsolete. The non-obsolete alternative is DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Boolean, IEnumerable(CustomAttributeBuilder)).

Defines a dynamic assembly using the specified name, access mode, storage directory, evidence, permission requests, and synchronization option.

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

[<ObsoleteAttribute("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")>]
abstract DefineDynamicAssembly : 
        name:AssemblyName * 
        access:AssemblyBuilderAccess * 
        dir:string * 
        evidence:Evidence * 
        requiredPermissions:PermissionSet * 
        optionalPermissions:PermissionSet * 
        refusedPermissions:PermissionSet * 
        isSynchronized:bool -> AssemblyBuilder 
[<ObsoleteAttribute("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")>]
override DefineDynamicAssembly : 
        name:AssemblyName * 
        access:AssemblyBuilderAccess * 
        dir:string * 
        evidence:Evidence * 
        requiredPermissions:PermissionSet * 
        optionalPermissions:PermissionSet * 
        refusedPermissions:PermissionSet * 
        isSynchronized:bool -> AssemblyBuilder 

Parameters

name
Type: System.Reflection.AssemblyName
The unique identity of the dynamic assembly.
access
Type: System.Reflection.Emit.AssemblyBuilderAccess
The mode in which the dynamic assembly will be accessed.
dir
Type: System.String
The name of the directory where the dynamic assembly will be saved. If dir is a null reference (Nothing in Visual Basic), the directory defaults to the current directory.
evidence
Type: System.Security.Policy.Evidence
The evidence supplied for the dynamic assembly. The evidence is used unaltered as the final set of evidence used for policy resolution.
requiredPermissions
Type: System.Security.PermissionSet
The required permissions request.
optionalPermissions
Type: System.Security.PermissionSet
The optional permissions request.
refusedPermissions
Type: System.Security.PermissionSet
The refused permissions request.
isSynchronized
Type: System.Boolean
true to synchronize the creation of modules, types, and members in the dynamic assembly; otherwise, false.

Return Value

Type: System.Reflection.Emit.AssemblyBuilder
A dynamic assembly with the specified name and features.

Implements

_AppDomain.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)

ExceptionCondition
ArgumentNullException

name is a null reference (Nothing in Visual Basic).

ArgumentException

The Name property of name is a null reference (Nothing in Visual Basic).

-or-

The Name property of name begins with white space, or contains a forward or backward slash.

AppDomainUnloadedException

The operation is attempted on an unloaded application domain.

The permission requests specified for requiredPermissions, optionalPermissions, and refusedPermissions are used only if evidence is also supplied, or if the dynamic assembly is saved and reloaded into memory.

NoteNote

During the development of code that emits dynamic assemblies, it is recommended that you include SecurityPermissionFlag.SkipVerification in refusedPermissions. Including SkipVerification in the refusedPermissions parameter ensures that the MSIL is verified. A limitation of this technique is that it also causes SecurityException to be thrown when used with code that demands full trust.

Only fully trusted callers can supply their evidence when defining a dynamic Assembly. The runtime will map the Evidence through the security policy to determine the granted permissions. Partially trusted callers must supply a null reference (Nothing in Visual Basic) for the evidence parameter. If evidence is a null reference (Nothing in Visual Basic), the runtime copies the permission sets, that is, the current grant and deny sets, from the caller's Assembly to the dynamic Assembly being defined and marks policy as resolved.

If the dynamic Assembly is saved to disk, subsequent loads will get grants based on policies associated with the location where the Assembly was saved.

If isSynchronized is true, the following methods of the resulting AssemblyBuilder will be synchronized: DefineDynamicModule, DefineResource, AddResourceFile, GetDynamicModule, SetEntryPoint, and Save. If two of these methods are called on different threads, one will block until the other completes.

NoteNote

In the .NET Framework versions 1.0, 1.1, and 2.0, the declarative security attributes applied to a dynamic assembly by using the requiredPermissions, optionalPermissions, and refusedPermissions parameters are stored in the old XML metadata format. See Emitting Declarative Security Attributes.

The following sample demonstrates the DefineDynamicAssembly method and AssemblyResolve event.

For this code example to run, you must provide the fully qualified assembly name. For information about how to obtain the fully qualified assembly name, see Assembly Names.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Obsolete (compiler warning) in 4

.NET Framework Client Profile

Supported in: 3.5 SP1
Obsolete (compiler warning) in 4

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.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft