static Assembly LoadAssembly(string name) { try { var assemblyStream = new BinaryReader(new FxStreamWrapper(ScriptHost.OpenHostFile(name + ".dll"))); var assemblyBytes = assemblyStream.ReadBytes((int)assemblyStream.BaseStream.Length); byte[] symbolBytes = null; try { var symbolStream = new BinaryReader(new FxStreamWrapper(ScriptHost.OpenHostFile(name + ".dll.mdb"))); symbolBytes = symbolStream.ReadBytes((int)symbolStream.BaseStream.Length); } catch { // nothing } return(CreateAssemblyInternal(assemblyBytes, symbolBytes)); } catch (Exception e) { Debug.WriteLine($"Exception loading assembly {name}: {e}"); } return(null); }
static Assembly LoadAssemblyInternal(string name) { try { var assemblyStream = new BinaryReader(new FxStreamWrapper(ScriptHost.OpenHostFile(name + ".dll"))); var assemblyBytes = assemblyStream.ReadBytes((int)assemblyStream.BaseStream.Length); byte[] symbolBytes = null; try { var symbolStream = new BinaryReader(new FxStreamWrapper(ScriptHost.OpenHostFile(name + ".dll.mdb"))); symbolBytes = symbolStream.ReadBytes((int)symbolStream.BaseStream.Length); } catch { try { var symbolStream = new BinaryReader(new FxStreamWrapper(ScriptHost.OpenHostFile(name + ".pdb"))); symbolBytes = symbolStream.ReadBytes((int)symbolStream.BaseStream.Length); } catch { // nothing } } return(CreateAssemblyInternal(name + ".dll", assemblyBytes, symbolBytes)); } catch (Exception e) { //Switching the FileNotFound to a NotImplemented tells mono to disable I18N support. //See: https://github.com/mono/mono/blob/8fee89e530eb3636325306c66603ba826319e8c5/mcs/class/corlib/System.Text/EncodingHelper.cs#L131 if (e is FileNotFoundException && string.Equals(name, "I18N", StringComparison.OrdinalIgnoreCase)) { throw new NotImplementedException("I18N not found", e); } Debug.WriteLine($"Exception loading assembly {name}: {e}"); } return(null); }
static Assembly LoadAssemblyInternal(string baseName, bool useSearchPaths = false) { var attemptPaths = new List <string>(); attemptPaths.Add(baseName); var exceptions = new StringBuilder(); if (useSearchPaths) { foreach (var path in ms_assemblySearchPaths) { attemptPaths.Add($"{path.Replace('\\', '/')}/{baseName}"); } } foreach (var name in attemptPaths) { try { byte[] assemblyBytes; using (var assemblyStream = new BinaryReader(new FxStreamWrapper(ScriptHost.OpenHostFile(name + ".dll")))) { assemblyBytes = assemblyStream.ReadBytes((int)assemblyStream.BaseStream.Length); } byte[] symbolBytes = null; try { using (var symbolStream = new BinaryReader(new FxStreamWrapper(ScriptHost.OpenHostFile(name + ".dll.mdb")))) { symbolBytes = symbolStream.ReadBytes((int)symbolStream.BaseStream.Length); } } catch { try { using (var symbolStream = new BinaryReader(new FxStreamWrapper(ScriptHost.OpenHostFile(name + ".pdb")))) { symbolBytes = symbolStream.ReadBytes((int)symbolStream.BaseStream.Length); } } catch { // nothing } } if (assemblyBytes != null) { var dirName = Path.GetDirectoryName(name); if (!string.IsNullOrWhiteSpace(dirName)) { ms_assemblySearchPaths.Add(dirName); } } return(CreateAssemblyInternal(name + ".dll", assemblyBytes, symbolBytes)); } catch (Exception e) { //Switching the FileNotFound to a NotImplemented tells mono to disable I18N support. //See: https://github.com/mono/mono/blob/8fee89e530eb3636325306c66603ba826319e8c5/mcs/class/corlib/System.Text/EncodingHelper.cs#L131 if (e is FileNotFoundException && string.Equals(name, "I18N", StringComparison.OrdinalIgnoreCase)) { throw new NotImplementedException("I18N not found", e); } exceptions.AppendLine($"Exception loading assembly {name}: {e}"); } } if (!baseName.Contains(".resources")) { Debug.WriteLine($"Could not load assembly {baseName} - loading exceptions: {exceptions}"); } return(null); }