AppDomain.DefineDynamicAssembly Method (AssemblyName, AssemblyBuilderAccess, Evidence)
Note: This API is now obsolete. The non-obsolete alternative is DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess).
Defines a dynamic assembly using the specified name, access mode, and evidence.
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 * evidence:Evidence -> 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 * evidence:Evidence -> AssemblyBuilder
- Type: System.Reflection.AssemblyName
The unique identity of the dynamic assembly.
- Type: System.Reflection.Emit.AssemblyBuilderAccess
The mode in which the dynamic assembly will be accessed.
- 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.
Return ValueType: System.Reflection.Emit.AssemblyBuilder
A dynamic assembly with the specified name and features.
Implements_AppDomain.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, Evidence)
name is a null reference (Nothing in Visual Basic).
The Name property of name is a null reference (Nothing in Visual Basic).
The Name property of name begins with white space, or contains a forward or backward slash.
The operation is attempted on an unloaded application domain.
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 evidence. 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.
This method should only be used to define a dynamic assembly in the current application domain. For more information, see the Load(AssemblyName) method overload.
During the development of code that emits dynamic assemblies, it is recommended that you use an overload of the DefineDynamicAssembly method that specifies evidence and permissions, supply the evidence you want the dynamic assembly to have, and 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.
First, the code example tries to create an instance of MyDynamicType by calling the CreateInstance method with an invalid assembly name, and catches the resulting exception.
The code example then adds an event handler for the AssemblyResolve event, and again tries to create an instance of MyDynamicType. During the call to CreateInstance, the AssemblyResolve event is raised for the invalid assembly. The event handler creates a dynamic assembly that contains a type named MyDynamicType, gives the type a parameterless constructor, and returns the new dynamic assembly. The call to CreateInstance then finishes successfully, and the constructor for MyDynamicType displays a message at the console.
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.