AppDomain::DefineDynamicAssembly Method (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
Note: This API is now obsolete. The non-obsolete alternative is DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Boolean, IEnumerable<CustomAttributeBuilder>).
Defines a dynamic assembly with the specified name, access mode, storage directory, evidence, permission requests, synchronization option, and custom attributes.
Assembly: mscorlib (in mscorlib.dll)
[ObsoleteAttribute(L"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.")] public: AssemblyBuilder^ DefineDynamicAssembly( AssemblyName^ name, AssemblyBuilderAccess access, String^ dir, Evidence^ evidence, PermissionSet^ requiredPermissions, PermissionSet^ optionalPermissions, PermissionSet^ refusedPermissions, bool isSynchronized, IEnumerable<CustomAttributeBuilder^>^ assemblyAttributes )
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 nullptr, the current directory is used.
- evidence
- Type: System.Security.Policy::Evidence
The evidence that is 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.
- assemblyAttributes
- Type: System.Collections.Generic::IEnumerable<CustomAttributeBuilder>
An enumerable list of attributes to be applied to the assembly, or nullptr if there are no attributes.
Return Value
Type: System.Reflection.Emit::AssemblyBuilderA dynamic assembly with the specified name and features.
| Exception | Condition |
|---|---|
| ArgumentNullException | name is nullptr. |
| ArgumentException | The Name property of name is nullptr. -or- The Name property of name starts with white space, or contains a forward or backward slash. |
| AppDomainUnloadedException | The operation is attempted on an unloaded application domain. |
Use this method overload to specify attributes that do not work correctly unless they are applied when a dynamic assembly is created. For example, security attributes such as SecurityTransparentAttribute and SecurityCriticalAttribute do not work correctly if they are added after a dynamic assembly has been created.
The permission requests specified for the requiredPermissions, optionalPermissions, and refusedPermissions parameters are used only if the evidence parameter is also supplied, or if the dynamic assembly is saved and reloaded into memory.
Note |
|---|
When you develop code that emits dynamic assemblies, we recommend that you include the SecurityPermissionFlag::SkipVerification flag in the refusedPermissions parameter. The inclusion of this flag ensures that the Microsoft intermediate language (MSIL) will be verified. This technique will detect the unintentional generation of unverifiable code, which otherwise is very difficult to detect. A limitation of this technique is that it also causes SecurityException to be thrown when it is used with code that demands full trust. |
Only fully trusted callers can supply evidence when defining a dynamic Assembly. The runtime maps the Evidence through the security policy to determine the granted permissions. Partially trusted callers must supply nullptr for the evidence parameter. If evidence is nullptr, the runtime copies the permission sets (that is, the current grant and deny sets) from the caller's assembly to the dynamic assembly that is being defined, and marks the policy as resolved.
If the dynamic assembly is saved to disk, subsequent loads will get grants based on policies that are associated with the location where the dynamic 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 is completed.
Note |
|---|
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. For more information about these attributes, see Emitting Declarative Security Attributes. |
This method overload is introduced in the .NET Framework version 3.5.
- SecurityPermission
to load an assembly with evidence. Associated enumeration: SecurityPermissionFlag::ControlEvidence.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, 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.
Note