partial void BindEcmaByteArray(byte[] rawAssembly, byte[] rawSymbolStore, ref AssemblyBindResult bindResult, ref Exception exception, ref bool?result) { // 1. Load byte[] into immutable array for use by PEReader/MetadataReader ImmutableArray <byte> assemblyData = ImmutableArray.Create(rawAssembly); PEReader pe = new PEReader(assemblyData); MetadataReader reader = pe.GetMetadataReader(); // 2. Create AssemblyName from MetadataReader RuntimeAssemblyName runtimeAssemblyName = reader.GetAssemblyDefinition().ToRuntimeAssemblyName(reader); AssemblyName asmName = new AssemblyName(); runtimeAssemblyName.CopyToAssemblyName(asmName); lock (s_ecmaLoadedAssemblies) { // 3. Attempt to bind to already loaded assembly if (Bind(asmName, out bindResult, out exception)) { result = true; return; } exception = null; // 4. If that fails, then add newly created metareader to global cache of byte array loaded modules PEInfo peinfo = new PEInfo(asmName, reader, pe); s_ecmaLoadedAssemblies.Add(peinfo); ModuleList moduleList = ModuleList.Instance; ModuleInfo newModuleInfo = new EcmaModuleInfo(moduleList.SystemModule.Handle, pe, reader); moduleList.RegisterModule(newModuleInfo); // 5. Then try to load by name again. This load should always succeed if (Bind(asmName, out bindResult, out exception)) { result = true; return; } result = false; Debug.Assert(exception != null); // We must have an error on load. At this time this could happen due to ambiguous name matching } }
public sealed override void InitializeAssemblyName(AssemblyName blank, String fullName) { RuntimeAssemblyName runtimeAssemblyName = AssemblyNameParser.Parse(fullName); runtimeAssemblyName.CopyToAssemblyName(blank); }