internal AssemblyBuilder(AppDomain domain,
AssemblyName name,
AssemblyBuilderAccess access,
String dir,
Evidence evidence,
PermissionSet requiredPermissions,
PermissionSet optionalPermissions,
PermissionSet refusedPermissions,
ref StackCrawlMark stackMark,
IEnumerable <CustomAttributeBuilder> unsafeAssemblyAttributes,
SecurityContextSource securityContextSource)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
if (access != AssemblyBuilderAccess.Run
#if FEATURE_REFLECTION_ONLY_LOAD
&& access != AssemblyBuilderAccess.ReflectionOnly
#endif // FEATURE_REFLECTION_ONLY_LOAD
&& access != AssemblyBuilderAccess.RunAndCollect
)
{
throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)access), nameof(access));
}
if (securityContextSource < SecurityContextSource.CurrentAppDomain ||
securityContextSource > SecurityContextSource.CurrentAssembly)
{
throw new ArgumentOutOfRangeException(nameof(securityContextSource));
}
// Clone the name in case the caller modifies it underneath us.
name = (AssemblyName)name.Clone();
// If the caller is trusted they can supply identity
// evidence for the new assembly. Otherwise we copy the
// current grant and deny sets from the caller's assembly,
// inject them into the new assembly and mark policy as
// resolved. If/when the assembly is persisted and
// reloaded, the normal rules for gathering evidence will
// be used.
if (evidence != null)
#pragma warning disable 618
{
new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
}
#pragma warning restore 618
// Scan the assembly level attributes for any attributes which modify how we create the
// assembly. Currently, we look for any attribute which modifies the security transparency
// of the assembly.
List <CustomAttributeBuilder> assemblyAttributes = null;
DynamicAssemblyFlags assemblyFlags = DynamicAssemblyFlags.None;
byte[] securityRulesBlob = null;
byte[] aptcaBlob = null;
if (unsafeAssemblyAttributes != null)
{
// Create a copy to ensure that it cannot be modified from another thread
// as it is used further below.
assemblyAttributes = new List <CustomAttributeBuilder>(unsafeAssemblyAttributes);
#pragma warning disable 618 // We deal with legacy attributes here as well for compat
foreach (CustomAttributeBuilder attribute in assemblyAttributes)
{
if (attribute.m_con.DeclaringType == typeof(SecurityTransparentAttribute))
{
assemblyFlags |= DynamicAssemblyFlags.Transparent;
}
else if (attribute.m_con.DeclaringType == typeof(SecurityCriticalAttribute))
{
{
assemblyFlags |= DynamicAssemblyFlags.AllCritical;
}
}
}
#pragma warning restore 618
}
m_internalAssemblyBuilder = (InternalAssemblyBuilder)nCreateDynamicAssembly(domain,
name,
evidence,
ref stackMark,
requiredPermissions,
optionalPermissions,
refusedPermissions,
securityRulesBlob,
aptcaBlob,
access,
assemblyFlags,
securityContextSource);
m_assemblyData = new AssemblyBuilderData(m_internalAssemblyBuilder,
name.Name,
access,
dir);
m_assemblyData.AddPermissionRequests(requiredPermissions,
optionalPermissions,
refusedPermissions);
#if FEATURE_APPX
if (AppDomain.ProfileAPICheck)
{
RuntimeAssembly creator = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
if (creator != null && !creator.IsFrameworkAssembly())
{
m_profileAPICheck = true;
}
}
#endif
// Make sure that ManifestModule is properly initialized
// We need to do this before setting any CustomAttribute
InitManifestModule();
if (assemblyAttributes != null)
{
foreach (CustomAttributeBuilder assemblyAttribute in assemblyAttributes)
{
SetCustomAttribute(assemblyAttribute);
}
}
}