// Constructor. Called from AppDomain.DefineDynamicAssembly. internal AssemblyBuilder(AssemblyName name, AssemblyBuilderAccess access, String directory, bool isSynchronized) { this.access = access; this.directory = (directory == null) ? "." : directory; this.isSynchronized = isSynchronized; this.saved = false; this.entryPoint = null; this.detachList = new ArrayList(); fileKind = PEFileKinds.Dll; Version version = name.Version; lock(typeof(AssemblyBuilder)) { if(version != null) { this.privateData = ClrAssemblyCreate (name.Name, version.Major, version.Minor, version.Build, version.Revision, access, out writer); } else { this.privateData = ClrAssemblyCreate (name.Name, 0, 0, 0, 0, access, out writer); } } if(this.privateData == IntPtr.Zero) { // The runtime engine disallowed dynamic assemblies. throw new SecurityException (_("Emit_NoDynamicAssemblies")); } }
private AssemblyBuilder CreateDynamicAssembly(string name, AssemblyBuilderAccess access) { AssemblyName myAsmName = new AssemblyName(); myAsmName.Name = name; AssemblyBuilder myAsmBuilder = AssemblyBuilder.DefineDynamicAssembly(myAsmName, access); return myAsmBuilder; }
internal AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access) { var realAba = EmitWrapper.Mscorlib.GetType("System.Reflection.Emit.AssemblyBuilderAccess"); var result = this.Invoke("DefineDynamicAssembly", new Type[] { typeof(AssemblyName), realAba }, name, access); return new AssemblyBuilder(result); }
private TypeBuilder GetCustomType(string name, AssemblyBuilderAccess access) { AssemblyName myAsmName = new AssemblyName(); myAsmName.Name = name; AssemblyBuilder myAsmBuilder = AssemblyBuilder.DefineDynamicAssembly(myAsmName, access); ModuleBuilder moduleBuilder = TestLibrary.Utilities.GetModuleBuilder(myAsmBuilder, TestModuleName); return moduleBuilder.DefineType(TestTypeName); }
protected void SetUp (AssemblyBuilderAccess mode) { AssemblyName assemblyName = new AssemblyName (); assemblyName.Name = ASSEMBLY_NAME; assembly = Thread.GetDomain ().DefineDynamicAssembly ( assemblyName, mode, Path.GetTempPath ()); module = assembly.DefineDynamicModule ("module1"); }
public AssemblyBuilder GetAssemblyBuilder() { if (_assemblyBuilder == null) { AssemblyBuilderAccess = AssemblyBuilderAccess.RunAndCollect; _assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly( new AssemblyName(_assemblyName), AssemblyBuilderAccess ); } return _assemblyBuilder; }
void SetUp (AssemblyBuilderAccess access) { AssemblyName assemblyName = new AssemblyName (); assemblyName.Name = ASSEMBLY_NAME; assembly = Thread.GetDomain ().DefineDynamicAssembly ( assemblyName, access, Path.GetTempPath ()); module = assembly.DefineDynamicModule ("module1"); typeCount = 0; }
public static Assembly GetRefEmitAssembly(string assemblyNameStr, AssemblyBuilderAccess builderType) { var assemblyName = new AssemblyName(assemblyNameStr); AssemblyBuilder builder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, builderType); ModuleBuilder moduleBuilder = builder.DefineDynamicModule("RefEmitModule"); TypeBuilder typeBuilder = moduleBuilder.DefineType("RefEmitTestType", TypeAttributes.Public); // Define "Assembly LoadStaticAssembly(string)" method that will load a static assembly MethodBuilder methodBuilder = typeBuilder.DefineMethod("LoadStaticAssembly", MethodAttributes.Public|MethodAttributes.Static, typeof(Assembly), new Type[]{typeof(string)}); ILGenerator ilGenerator = methodBuilder.GetILGenerator(); // Generate the following code: // // AssemblyName name = new AssemblyName(name); // name is the argument passed to LoadStaticAssembly // Assembly.Load(name); // Declare the locals LocalBuilder localAssemblyName = ilGenerator.DeclareLocal(typeof(AssemblyName)); LocalBuilder localAssembly = ilGenerator.DeclareLocal(typeof(Assembly)); // Fetch reference to AssemblyName ctor we want to invoke ConstructorInfo ctorAssemblyName = TypeExtensions.GetConstructor(typeof(System.Reflection.AssemblyName), new Type[] {typeof(string)}); // Load incoming assemblyname string ilGenerator.Emit(OpCodes.Ldarg_0); // Create new object of the type AssemblyName ilGenerator.Emit(OpCodes.Newobj, ctorAssemblyName); // "this" for assemblyname instance is already at the top of evaluation stack. // // Invoke Assembly.Load MethodInfo miAssemblyLoad = TypeExtensions.GetMethod(typeof(System.Reflection.Assembly), "Load", new Type[] {typeof(System.Reflection.AssemblyName)}); ilGenerator.Emit(OpCodes.Call, miAssemblyLoad); // Return the reference to the loaded assembly ilGenerator.Emit(OpCodes.Ret); // Generate the type typeBuilder.CreateTypeInfo().AsType(); // Return the generated assembly return builder; }
public DynamicAssembly (String assemblyName, String moduleName, AssemblyBuilderAccess access = AssemblyBuilderAccess.RunAndSave) { this.assemblyName = assemblyName; this.moduleName = moduleName; // Define dynamic assembly AssemblyName name = new AssemblyName { Name = this.assemblyName, Version = Assembly.GetExecutingAssembly().GetName().Version }; this.assembly = AppDomain.CurrentDomain.DefineDynamicAssembly (name, access); // Define dynamic module if (access == AssemblyBuilderAccess.RunAndSave || access == AssemblyBuilderAccess.Save) { // Persistent this.module = this.assembly.DefineDynamicModule (this.moduleName, this.assemblyName + ".dll"); } else { // Transient this.module = this.assembly.DefineDynamicModule (this.moduleName); } }
public ProxyModule(string assemblyName, AssemblyBuilderAccess access) { _assemblyName = assemblyName; _assemblyNameWithExt = _assemblyName + ".dll"; switch (access) { case AssemblyBuilderAccess.Run: break; case AssemblyBuilderAccess.RunAndSave: break; case AssemblyBuilderAccess.RunAndCollect: break; default: throw new ArgumentOutOfRangeException("access", "Run, RunAndSave, or RunAndCollect are the only permitted options"); } _access = access; _factories = new object[_factoryTypeCount]; }
public ProxyContext(AssemblyBuilderAccess access, bool verify, bool generateDebugging) : this() { if ((access & AssemblyBuilderAccess.Run) != AssemblyBuilderAccess.Run) { throw new ArgumentException( "Invalid access value - the assembly must have Run access.", "access"); } if (verify && ((access & AssemblyBuilderAccess.Save) != AssemblyBuilderAccess.Save)) { throw new ArgumentException("Verification cannot be done on a transient assembly.", "verify"); } // TODO - I'm not sure if debugging can be done on transient assemblies... this.Access = access; this.Verify = verify; this.GenerateDebugging = generateDebugging; }
internal AssemblyBuilderData( InternalAssemblyBuilder assembly, String strAssemblyName, AssemblyBuilderAccess access, String dir) { m_assembly = assembly; m_strAssemblyName = strAssemblyName; m_access = access; m_moduleBuilderList = new List<ModuleBuilder>(); m_resWriterList = new List<ResWriterData>(); //Init to null/0 done for you by the CLR. FXCop has spoken if (dir == null && access != AssemblyBuilderAccess.Run) m_strDir = Environment.CurrentDirectory; else m_strDir = dir; m_peFileKind = PEFileKinds.Dll; }
void SetUp (AssemblyBuilderAccess access) { AssemblyName assemblyName = new AssemblyName (); assemblyName.Name = ASSEMBLY_NAME; assembly = AppDomain.CurrentDomain.DefineDynamicAssembly ( assemblyName, access, Path.GetTempPath ()); module = assembly.DefineDynamicModule ("module1"); tb = module.DefineType ("Bar"); GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T"); cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, new Type [] { typeof (string), typeof (int) }); ILGenerator ig = cb.GetILGenerator (); ig.Emit (OpCodes.Ret); typeBarOfInt32 = tb.MakeGenericType (typeof (int)); ci = TypeBuilder.GetConstructor (typeBarOfInt32, cb); }
internal AssemblyBuilderData( Assembly assembly, String strAssemblyName, AssemblyBuilderAccess access, String dir) { m_assembly = assembly; m_strAssemblyName = strAssemblyName; m_access = access; m_moduleBuilderList = new ArrayList(); m_resWriterList = new ArrayList(); m_publicComTypeList = null; m_CABuilders = null; m_CABytes = null; m_CACons = null; m_iPublicComTypeCount = 0; m_iCABuilder = 0; m_iCAs = 0; m_entryPointModule = null; m_isSaved = false; if (dir == null && access != AssemblyBuilderAccess.Run) m_strDir = Environment.CurrentDirectory; else m_strDir = dir; m_RequiredPset = null; m_OptionalPset = null; m_RefusedPset = null; m_isSynchronized = false; m_InMemoryAssemblyModule = null; m_OnDiskAssemblyModule = null; m_peFileKind = PEFileKinds.Dll; m_entryPointMethod = null; m_ISymWrapperAssembly = null; }
public AssemblyBuilder DefineDynamicAssembly( AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence) { Contract.Ensures(Contract.Result<AssemblyBuilder>() != null); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return InternalDefineDynamicAssembly(name, access, dir, evidence, null, null, null, ref stackMark, null, SecurityContextSource.CurrentAssembly); }
private static ModuleBuilder CreateDynamicModule(AssemblyBuilderAccess access, AssemblyIdentity name, string fileName) { var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(name.ToAssemblyName(), access); if (DisableJitOptimizations) { assemblyBuilder.SetCustomAttribute(new CustomAttributeBuilder( typeof(DebuggableAttribute).GetConstructor(new[] { typeof(DebuggableAttribute.DebuggingModes) }), new object[] { DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations })); } const string moduleName = "InteractiveModule"; if (access == AssemblyBuilderAccess.RunAndSave) { return assemblyBuilder.DefineDynamicModule(moduleName, fileName, emitSymbolInfo: false); } else { return assemblyBuilder.DefineDynamicModule(moduleName, emitSymbolInfo: false); } }
public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, System.Security.Policy.Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, bool isSynchronized, IEnumerable<CustomAttributeBuilder> assemblyAttributes) { StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller; return this.InternalDefineDynamicAssembly(name, access, dir, evidence, requiredPermissions, optionalPermissions, refusedPermissions, ref lookForMyCaller, assemblyAttributes); }
public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions) { StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller; return this.InternalDefineDynamicAssembly(name, access, null, null, requiredPermissions, optionalPermissions, refusedPermissions, ref lookForMyCaller, null); }
public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir) { StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller; return this.InternalDefineDynamicAssembly(name, access, dir, null, null, null, null, ref lookForMyCaller, null); }
private extern Assembly nCreateDynamicAssembly(AssemblyName name, System.Security.Policy.Evidence identity, ref StackCrawlMark stackMark, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, AssemblyBuilderAccess access, DynamicAssemblyFlags flags);
public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, IEnumerable<CustomAttributeBuilder> assemblyAttributes, SecurityContextSource securityContextSource) { return DefineDynamicAssembly (name, access, assemblyAttributes); }
[InlineData((AssemblyBuilderAccess)6)] // ReflectionOnly (not supported) public void DefineDynamicAssembly_CoreclrNotSupportedAccess_ThrowsArgumentException(AssemblyBuilderAccess access) { DefineDynamicAssembly_InvalidAccess_ThrowsArgumentException(access); }
public void DefineDynamicAssembly_InvalidAccess_ThrowsArgumentException(AssemblyBuilderAccess access) { AssertExtensions.Throws <ArgumentException>("access", () => AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Name"), access)); AssertExtensions.Throws <ArgumentException>("access", () => AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Name"), access, new CustomAttributeBuilder[0])); }
public void DefineDynamicAssembly_AssemblyName_AssemblyBuilderAccess(AssemblyName name, AssemblyBuilderAccess access) { AssemblyBuilder assembly = AssemblyBuilder.DefineDynamicAssembly(name, access); VerifyAssemblyBuilder(assembly, name, new CustomAttributeBuilder[0]); }
public void DefineDynamicAssembly_AssemblyName_AssemblyBuilderAccess_CustomAttributeBuilder(AssemblyName name, AssemblyBuilderAccess access, IEnumerable <CustomAttributeBuilder> attributes) { AssemblyBuilder assembly = AssemblyBuilder.DefineDynamicAssembly(name, access, attributes); VerifyAssemblyBuilder(assembly, name, attributes); }
// Silverlight doesn't implement this. internal static AssemblyBuilder DefineDynamicAssembly(this AppDomain appDomain, AssemblyName assemblyName, AssemblyBuilderAccess access, CustomAttributeBuilder[] attributeBuilders) { return(appDomain.DefineDynamicAssembly(assemblyName, access)); }
private static extern Assembly nCreateDynamicAssembly(AppDomain domain, AssemblyName name, ref StackCrawlMark stackMark, AssemblyBuilderAccess access);
[DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod. public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return(InternalDefineDynamicAssembly(name, access, ref stackMark, null)); }
private Type CreateUncachedProxyType(Type[] baseInterfaces, Type baseType) { AppDomain currentDomain = AppDomain.CurrentDomain; string typeName = string.Format("{0}Proxy", baseType.Name); string assemblyName = string.Format("{0}Assembly", typeName); string moduleName = string.Format("{0}Module", typeName); AssemblyName name = new AssemblyName(assemblyName); #if DEBUG && !SILVERLIGHT AssemblyBuilderAccess access = AssemblyBuilderAccess.RunAndSave; #else AssemblyBuilderAccess access = AssemblyBuilderAccess.Run; #endif AssemblyBuilder assemblyBuilder = currentDomain.DefineDynamicAssembly(name, access); #if DEBUG && !SILVERLIGHT ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(moduleName, string.Format("{0}.mod", moduleName), true); #else ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(moduleName); #endif TypeAttributes typeAttributes = TypeAttributes.AutoClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.BeforeFieldInit; List <Type> interfaceList = new List <Type>(); if (baseInterfaces != null && baseInterfaces.Length > 0) { interfaceList.AddRange(baseInterfaces); } // Use the proxy dummy as the base type // since we're not inheriting from any class type Type parentType = baseType; if (baseType.IsInterface) { parentType = typeof(ProxyDummy); interfaceList.Add(baseType); } // Add any inherited interfaces Type[] interfaces = interfaceList.ToArray(); foreach (Type interfaceType in interfaces) { BuildInterfaceList(interfaceType, interfaceList); } #if !SILVERLIGHT // Add the ISerializable interface so that it can be implemented if (!interfaceList.Contains(typeof(ISerializable))) { interfaceList.Add(typeof(ISerializable)); } #endif TypeBuilder typeBuilder = moduleBuilder.DefineType(typeName, typeAttributes, parentType, interfaceList.ToArray()); ConstructorBuilder defaultConstructor = DefineConstructor(typeBuilder); // Implement IProxy ProxyImplementor implementor = new ProxyImplementor(); implementor.ImplementProxy(typeBuilder); MethodInfo[] methods = baseType.GetMethods(BindingFlags.Public | BindingFlags.Instance); List <MethodInfo> proxyList = new List <MethodInfo>(); BuildMethodList(interfaceList, methods, proxyList); Debug.Assert(_proxyMethodBuilder != null, "ProxyMethodBuilder cannot be null"); FieldInfo interceptorField = implementor.InterceptorField; foreach (MethodInfo method in proxyList) { #if !SILVERLIGHT // Provide a custom implementation of ISerializable // instead of redirecting it back to the interceptor if (method.DeclaringType == typeof(ISerializable)) { continue; } #endif _proxyMethodBuilder.CreateProxiedMethod(interceptorField, method, typeBuilder); } #if !SILVERLIGHT // Make the proxy serializable AddSerializationSupport(baseType, baseInterfaces, typeBuilder, interceptorField, defaultConstructor); #endif Type proxyType = typeBuilder.CreateType(); #if DEBUG_PROXY_OUTPUT assemblyBuilder.Save("generatedAssembly.dll"); #endif return(proxyType); }
public static AssemblyBuilder DefineDynamicAssembly(AssemblyName assName, AssemblyBuilderAccess access) { return(AssemblyBuilder.DefineDynamicAssembly(assName, access)); }
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public AssemblyBuilder DefineDynamicAssembly( AssemblyName name, AssemblyBuilderAccess access, String dir, bool isSynchronized, IEnumerable<CustomAttributeBuilder> assemblyAttributes) { Contract.Ensures(Contract.Result<AssemblyBuilder>() != null); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return InternalDefineDynamicAssembly(name, access, dir, null, null, null, null, ref stackMark, assemblyAttributes, SecurityContextSource.CurrentAssembly); }
internal AssemblyBuilder DefineInternalDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access) { return new AssemblyBuilder (name, null, access, true); }
public static AssemblyBuilder DefineDynamicAssembly(AssemblyName assName, AssemblyBuilderAccess access) { return(AppDomain.CurrentDomain.DefineDynamicAssembly(assName, access)); }
public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, IEnumerable<CustomAttributeBuilder> assemblyAttributes) { StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller; return this.InternalDefineDynamicAssembly(name, access, null, null, null, null, null, ref lookForMyCaller, assemblyAttributes); }
public OrmAssemblySqlWindows(string assemblyName, string assemblyFileName, AssemblyBuilderAccess assemblyBuilderAccess) : base(assemblyName, assemblyFileName, assemblyBuilderAccess) { }
public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, System.Security.Policy.Evidence evidence) { StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller; return this.InternalDefineDynamicAssembly(name, access, dir, evidence, null, null, null, ref lookForMyCaller, null); }
public static AssemblyBuilder DefineDynamicAssembly(this AppDomain _, AssemblyName assemblyName, AssemblyBuilderAccess assemblyBuilderAccess) { return(AssemblyBuilder.DefineDynamicAssembly(assemblyName, assemblyBuilderAccess)); }
public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, System.Security.Policy.Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions) { StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller; return this.InternalDefineDynamicAssembly(name, access, dir, evidence, requiredPermissions, optionalPermissions, refusedPermissions, ref lookForMyCaller, null); }
public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, IEnumerable <CustomAttributeBuilder> assemblyAttributes) { return(new Universe().DefineDynamicAssembly(name, access, assemblyAttributes)); }
internal AssemblyBuilder InternalDefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, System.Security.Policy.Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, ref StackCrawlMark stackMark, IEnumerable<CustomAttributeBuilder> unsafeAssemblyAttributes) { lock (typeof(AssemblyBuilderLock)) { AssemblyBuilder builder2; if (name == null) { throw new ArgumentNullException("name"); } if (((access != AssemblyBuilderAccess.Run) && (access != AssemblyBuilderAccess.Save)) && ((access != AssemblyBuilderAccess.RunAndSave) && (access != AssemblyBuilderAccess.ReflectionOnly))) { throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", new object[] { (int) access }), "access"); } if (name.KeyPair != null) { name.SetPublicKey(name.KeyPair.PublicKey); } if (evidence != null) { new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand(); } List<CustomAttributeBuilder> list = null; DynamicAssemblyFlags none = DynamicAssemblyFlags.None; if (unsafeAssemblyAttributes != null) { list = new List<CustomAttributeBuilder>(unsafeAssemblyAttributes); foreach (CustomAttributeBuilder builder in list) { if (builder.m_con.DeclaringType == typeof(SecurityTransparentAttribute)) { none |= DynamicAssemblyFlags.Transparent; } } } builder2 = new AssemblyBuilder((AssemblyBuilder) this.nCreateDynamicAssembly(name, evidence, ref stackMark, requiredPermissions, optionalPermissions, refusedPermissions, access, none)) { m_assemblyData = new AssemblyBuilderData(builder2, name.Name, access, dir) }; builder2.m_assemblyData.AddPermissionRequests(requiredPermissions, optionalPermissions, refusedPermissions); if (list != null) { foreach (CustomAttributeBuilder builder3 in list) { builder2.SetCustomAttribute(builder3); } } builder2.m_assemblyData.GetInMemoryAssemblyModule(); return builder2; } }
public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access) { return(new Universe().DefineDynamicAssembly(name, access)); }
internal AssemblyBuilder (AssemblyName n, string directory, AssemblyBuilderAccess access, bool corlib_internal) { /* This is obsolete now, as mcs doesn't use SRE any more */ if ((access & COMPILER_ACCESS) != 0) throw new NotImplementedException ("COMPILER_ACCESS is no longer supperted, use a newer mcs."); if (!Enum.IsDefined (typeof (AssemblyBuilderAccess), access)) throw new ArgumentException (string.Format (CultureInfo.InvariantCulture, "Argument value {0} is not valid.", (int) access), "access"); name = n.Name; this.access = (uint)access; flags = (uint) n.Flags; // don't call GetCurrentDirectory for Run-only builders (CAS may not like that) if (IsSave && (directory == null || directory.Length == 0)) { dir = Directory.GetCurrentDirectory (); } else { dir = directory; } /* Set defaults from n */ if (n.CultureInfo != null) { culture = n.CultureInfo.Name; versioninfo_culture = n.CultureInfo.Name; } Version v = n.Version; if (v != null) { version = v.ToString (); } if (n.KeyPair != null) { // full keypair is available (for signing) sn = n.KeyPair.StrongName (); } else { // public key is available (for delay-signing) byte[] pk = n.GetPublicKey (); if ((pk != null) && (pk.Length > 0)) { sn = new Mono.Security.StrongName (pk); } } if (sn != null) flags |= (uint) AssemblyNameFlags.PublicKey; this.corlib_internal = corlib_internal; if (sn != null) { this.pktoken = new byte[sn.PublicKeyToken.Length * 2]; int pkti = 0; foreach (byte pkb in sn.PublicKeyToken) { string part = pkb.ToString("x2"); this.pktoken[pkti++] = (byte)part[0]; this.pktoken[pkti++] = (byte)part[1]; } } basic_init (this); }
public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access) #if NET40 => AppDomain.CurrentDomain.DefineDynamicAssembly(name, access);
public AssemblyBuilder DefineDynamicAssembly( AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, bool isSynchronized) { Contract.Ensures(Contract.Result<AssemblyBuilder>() != null); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return InternalDefineDynamicAssembly(name, access, dir, evidence, requiredPermissions, optionalPermissions, refusedPermissions, ref stackMark, null, SecurityContextSource.CurrentAssembly); }
public static void LoadRefEmitAssemblyInLoadContext(AssemblyLoadContext loadContext, AssemblyBuilderAccess builderType) { // Load this assembly in custom LoadContext var assemblyNameStr = "System.Runtime.Loader.Noop.Assembly.dll"; // Load the assembly in the specified load context var asmTargetAsm = loadContext.LoadFromAssemblyPath(Path.Combine(s_loadFromPath, assemblyNameStr)); var creatorLoadContext = AssemblyLoadContext.GetLoadContext(asmTargetAsm); Assert.Equal(loadContext, creatorLoadContext); // Get reference to the helper method that will RefEmit an assembly and return reference to it. Type type = asmTargetAsm.GetType("System.Runtime.Loader.Tests.TestClass"); var method = System.Reflection.TypeExtensions.GetMethod(type, "GetRefEmitAssembly"); // Use the helper to generate an assembly var assemblyNameRefEmit = "RefEmitTestAssembly"; var asmRefEmitLoaded = (Assembly)method.Invoke(null, new object[] { assemblyNameRefEmit, builderType }); Assert.NotNull(asmRefEmitLoaded); // Assert that Dynamically emitted assemblies load context is the same as that of the assembly // that created them. var loadContextRefEmitAssembly = AssemblyLoadContext.GetLoadContext(asmRefEmitLoaded); Assert.Equal(creatorLoadContext, loadContextRefEmitAssembly); // Invoke the method that will trigger a static load in the dynamically generated assembly. Type typeRefEmit = asmRefEmitLoaded.GetType("RefEmitTestType"); method = System.Reflection.TypeExtensions.GetMethod(typeRefEmit, "LoadStaticAssembly"); Assert.NotNull(method); // Invoke the method to load the current assembly from the temp location var assemblyStaticToLoad = typeof(RefEmitLoadContext).GetTypeInfo().Assembly.GetName().Name; var asmRefEmitLoadedStatic = method.Invoke(null, new object[] { assemblyStaticToLoad }); Assert.NotNull(asmRefEmitLoadedStatic); // Load context of the statically loaded assembly is the custom load context in which dynamic assembly was created Assert.Equal(loadContextRefEmitAssembly, AssemblyLoadContext.GetLoadContext((Assembly)asmRefEmitLoadedStatic)); // Enumerate the assemblies in the AppDomain and confirm that the Dynamically generated assembly is present. var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies(); bool fDynamicAssemblyFound = false; foreach (Assembly asm in loadedAssemblies) { if (asmRefEmitLoaded == asm) { if (asm.FullName == asmRefEmitLoaded.FullName) { fDynamicAssemblyFound = true; break; } } } Assert.Equal(true, fDynamicAssemblyFound); }
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable private AssemblyBuilder InternalDefineDynamicAssembly( AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, ref StackCrawlMark stackMark, IEnumerable<CustomAttributeBuilder> assemblyAttributes, SecurityContextSource securityContextSource) { return AssemblyBuilder.InternalDefineDynamicAssembly(name, access, dir, evidence, requiredPermissions, optionalPermissions, refusedPermissions, ref stackMark, assemblyAttributes, securityContextSource); }
static AssemblyBuilder smethod_27(AppDomain appDomain_0, AssemblyName assemblyName_0, AssemblyBuilderAccess assemblyBuilderAccess_0) { return(appDomain_0.DefineDynamicAssembly(assemblyName_0, assemblyBuilderAccess_0)); }