// Loads the assembly with a COFF based IMAGE containing // an emitted assembly. The assembly is loaded into a fully isolated ALC with resolution fully deferred to the AssemblyLoadContext.Default. // The second parameter is the raw bytes representing the symbol store that matches the assembly. public static Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore) { if (rawAssembly == null) { throw new ArgumentNullException(nameof(rawAssembly)); } if (rawAssembly.Length == 0) { throw new BadImageFormatException(SR.BadImageFormat_BadILFormat); } #if FEATURE_APPX if (ApplicationModel.IsUap) { throw new NotSupportedException(SR.Format(SR.NotSupported_AppX, "Assembly.Load(byte[], ...)")); } #endif SerializationInfo.ThrowIfDeserializationInProgress("AllowAssembliesFromByteArrays", ref s_cachedSerializationSwitch); AssemblyLoadContext alc = new IndividualAssemblyLoadContext(); return(alc.InternalLoad(rawAssembly, rawSymbolStore)); }
public static Assembly LoadFile(string path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } #if FEATURE_APPX if (ApplicationModel.IsUap) { throw new NotSupportedException(SR.Format(SR.NotSupported_AppX, "Assembly.LoadFile")); } #endif if (PathInternal.IsPartiallyQualified(path)) { throw new ArgumentException(SR.Argument_AbsolutePathRequired, nameof(path)); } string normalizedPath = Path.GetFullPath(path); Assembly result; lock (s_loadfile) { if (s_loadfile.TryGetValue(normalizedPath, out result)) { return(result); } AssemblyLoadContext alc = new IndividualAssemblyLoadContext(); result = alc.LoadFromAssemblyPath(normalizedPath); s_loadfile.Add(normalizedPath, result); } return(result); }
public static Assembly LoadFile(string path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (PathInternal.IsPartiallyQualified(path)) { throw new ArgumentException(SR.Format(SR.Argument_AbsolutePathRequired, path), nameof(path)); } string normalizedPath = Path.GetFullPath(path); Assembly?result; lock (s_loadfile) { if (s_loadfile.TryGetValue(normalizedPath, out result)) { return(result); } AssemblyLoadContext alc = new IndividualAssemblyLoadContext(string.Format("Assembly.LoadFile({0})", normalizedPath)); result = alc.LoadFromAssemblyPath(normalizedPath); s_loadfile.Add(normalizedPath, result); } return(result); }
public static Assembly LoadFile(String path) { Contract.Ensures(Contract.Result <Assembly>() != null); Contract.Ensures(!Contract.Result <Assembly>().ReflectionOnly); AppDomain.CheckLoadFileSupported(); Assembly result = null; if (path == null) { throw new ArgumentNullException(nameof(path)); } if (PathInternal.IsPartiallyQualified(path)) { throw new ArgumentException(Environment.GetResourceString("Argument_AbsolutePathRequired"), nameof(path)); } string normalizedPath = Path.GetFullPath(path); lock (s_loadfile) { if (s_loadfile.TryGetValue(normalizedPath, out result)) { return(result); } AssemblyLoadContext alc = new IndividualAssemblyLoadContext(); result = alc.LoadFromAssemblyPath(normalizedPath); s_loadfile.Add(normalizedPath, result); } return(result); }
public static Assembly LoadFile(String path) { AppDomain.CheckLoadFileSupported(); Assembly result = null; if (path == null) { throw new ArgumentNullException(nameof(path)); } if (PathInternal.IsPartiallyQualified(path)) { throw new ArgumentException(SR.Argument_AbsolutePathRequired, nameof(path)); } string normalizedPath = Path.GetFullPath(path); lock (s_loadfile) { if (s_loadfile.TryGetValue(normalizedPath, out result)) { return(result); } AssemblyLoadContext alc = new IndividualAssemblyLoadContext(); result = alc.LoadFromAssemblyPath(normalizedPath); s_loadfile.Add(normalizedPath, result); } return(result); }
[System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod public static Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore) { AppDomain.CheckLoadByteArraySupported(); if (rawAssembly == null) throw new ArgumentNullException(nameof(rawAssembly)); AssemblyLoadContext alc = new IndividualAssemblyLoadContext(); MemoryStream assemblyStream = new MemoryStream(rawAssembly); MemoryStream symbolStream = (rawSymbolStore != null) ? new MemoryStream(rawSymbolStore) : null; return alc.LoadFromStream(assemblyStream, symbolStream); }
[System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod public static Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore) { Contract.Ensures(Contract.Result <Assembly>() != null); Contract.Ensures(!Contract.Result <Assembly>().ReflectionOnly); AppDomain.CheckLoadByteArraySupported(); if (rawAssembly == null) { throw new ArgumentNullException(nameof(rawAssembly)); } AssemblyLoadContext alc = new IndividualAssemblyLoadContext(); MemoryStream assemblyStream = new MemoryStream(rawAssembly); MemoryStream symbolStream = (rawSymbolStore != null) ? new MemoryStream(rawSymbolStore) : null; return(alc.LoadFromStream(assemblyStream, symbolStream)); }
// Loads the assembly with a COFF based IMAGE containing // an emitted assembly. The assembly is loaded into a fully isolated ALC with resolution fully deferred to the AssemblyLoadContext.Default. // The second parameter is the raw bytes representing the symbol store that matches the assembly. public static Assembly Load(byte[] rawAssembly, byte[]?rawSymbolStore) { if (rawAssembly == null) { throw new ArgumentNullException(nameof(rawAssembly)); } if (rawAssembly.Length == 0) { throw new BadImageFormatException(SR.BadImageFormat_BadILFormat); } SerializationInfo.ThrowIfDeserializationInProgress("AllowAssembliesFromByteArrays", ref s_cachedSerializationSwitch); AssemblyLoadContext alc = new IndividualAssemblyLoadContext("Assembly.Load(byte[], ...)"); return(alc.InternalLoad(rawAssembly, rawSymbolStore)); }
// Loads the assembly with a COFF based IMAGE containing // an emitted assembly. The assembly is loaded into a fully isolated ALC with resolution fully deferred to the AssemblyLoadContext.Default. // The second parameter is the raw bytes representing the symbol store that matches the assembly. public static Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore) { if (rawAssembly == null) { throw new ArgumentNullException(nameof(rawAssembly)); } #if FEATURE_APPX if (ApplicationModel.IsUap) { throw new NotSupportedException(SR.Format(SR.NotSupported_AppX, "Assembly.Load(byte[], ...)")); } #endif AssemblyLoadContext alc = new IndividualAssemblyLoadContext(); MemoryStream assemblyStream = new MemoryStream(rawAssembly); MemoryStream symbolStream = (rawSymbolStore != null) ? new MemoryStream(rawSymbolStore) : null; return(alc.LoadFromStream(assemblyStream, symbolStream)); }
/// <summary> /// Return assemblies from the default load context and the 'individual' load contexts. /// The 'individual' load contexts are the ones holding assemblies loaded via 'Assembly.Load(byte[])' and 'Assembly.LoadFile'. /// Assemblies loaded in any custom load contexts are not consider visible to PowerShell to avoid type identity issues. /// </summary> private static IEnumerable <Assembly> GetPSVisibleAssemblies() { const string IndividualAssemblyLoadContext = "System.Runtime.Loader.IndividualAssemblyLoadContext"; foreach (Assembly assembly in AssemblyLoadContext.Default.Assemblies) { if (!assembly.FullName.StartsWith(TypeDefiner.DynamicClassAssemblyFullNamePrefix, StringComparison.Ordinal)) { yield return(assembly); } } foreach (AssemblyLoadContext context in AssemblyLoadContext.All) { if (IndividualAssemblyLoadContext.Equals(context.GetType().FullName, StringComparison.Ordinal)) { foreach (Assembly assembly in context.Assemblies) { yield return(assembly); } } } }
// Loads the assembly with a COFF based IMAGE containing // an emitted assembly. The assembly is loaded into a fully isolated ALC with resolution fully deferred to the AssemblyLoadContext.Default. // The second parameter is the raw bytes representing the symbol store that matches the assembly. public static Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore) { if (rawAssembly == null) { throw new ArgumentNullException(nameof(rawAssembly)); } #if FEATURE_APPX if (ApplicationModel.IsUap) { throw new NotSupportedException(SR.Format(SR.NotSupported_AppX, "Assembly.Load(byte[], ...)")); } #endif SerializationInfo.ThrowIfDeserializationInProgress("AllowAssembliesFromByteArrays", ref s_cachedSerializationSwitch); AssemblyLoadContext alc = new IndividualAssemblyLoadContext(); MemoryStream assemblyStream = new MemoryStream(rawAssembly); MemoryStream symbolStream = (rawSymbolStore != null) ? new MemoryStream(rawSymbolStore) : null; return(alc.LoadFromStream(assemblyStream, symbolStream)); }