AppDomain.DefineDynamicAssembly Method (AssemblyName, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
Defines a dynamic assembly with the specified name, access mode, and custom attributes.
Assembly: mscorlib (in mscorlib.dll)
member DefineDynamicAssembly : name:AssemblyName * access:AssemblyBuilderAccess * assemblyAttributes:IEnumerable<CustomAttributeBuilder> -> AssemblyBuilder
The unique identity of the dynamic assembly.
The access mode for the dynamic assembly.
Return ValueType: System.Reflection.Emit.AssemblyBuilder
A dynamic assembly with the specified name and features.
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.
This method should be used only to define a dynamic assembly in the current application domain. For more information about this restriction, see the Load(AssemblyName) method overload.
This method overload is introduced in the .NET Framework 3.5.
The following code sample shows how to create a dynamic assembly that has the SecurityTransparentAttribute. The attribute must be specified as an element of an array of CustomAttributeBuilder objects.
The first step in creating the CustomAttributeBuilder is to obtain a constructor for the attribute. The constructor has no parameters, so the GetConstructor method is called with an empty array of Type objects to represent the types of the parameters. The second step is to pass the resulting ConstructorInfo object to the constructor for the CustomAttributeBuilder class, together with an empty array of type Object to represent the arguments.
The resulting CustomAttributeBuilder is then passed to the method as the only element of an array.
The example code defines a module and a type in the new dynamic assembly, and then displays the assembly's attributes.
Available since 2.0