public virtual AssemblyDefinition Load(string fileName) { if (!File.Exists(fileName)) { return(null); } AssemblyDefinition assembly; var name = Path.GetFileNameWithoutExtension(fileName); if (cache.TryGetValue(name, out assembly)) { return(assembly); } try { fileName = Target.GetRealPath(fileName); // Check the architecture-specific directory if (Path.GetDirectoryName(fileName) == FrameworkDirectory && !string.IsNullOrEmpty(ArchDirectory)) { var archName = Path.Combine(ArchDirectory, Path.GetFileName(fileName)); if (File.Exists(archName)) { fileName = archName; } } var parameters = CreateDefaultReaderParameters(fileName); try { assembly = ModuleDefinition.ReadModule(fileName, parameters).Assembly; params_cache [assembly.Name.ToString()] = parameters; if (!assembly.MainModule.HasSymbols) { // We Cecil didn't load symbols, but there's a pdb, then something went wrong loading it (maybe an old-style pdb?). // Warn about this. var pdb = Path.ChangeExtension(fileName, "pdb"); if (File.Exists(pdb)) { ErrorHelper.Show(ErrorHelper.CreateWarning(178, Errors.MX0178, fileName)); } } } catch (SymbolsNotMatchingException) { parameters.ReadSymbols = false; parameters.SymbolReaderProvider = null; assembly = ModuleDefinition.ReadModule(fileName, parameters).Assembly; // only report the warning (on symbols) if we can actually load the assembly itself (otherwise it's more confusing than helpful) ErrorHelper.Show(ErrorHelper.CreateWarning(129, Errors.MX0129, fileName)); } } catch (Exception e) { throw new ProductException(9, true, e, Errors.MX0009, fileName); } return(CacheAssembly(assembly)); }
public virtual AssemblyDefinition Load(string fileName) { if (!File.Exists(fileName)) { return(null); } AssemblyDefinition assembly; var name = Path.GetFileNameWithoutExtension(fileName); if (cache.TryGetValue(name, out assembly)) { return(assembly); } try { fileName = Target.GetRealPath(fileName); // Check the architecture-specific directory if (Path.GetDirectoryName(fileName) == FrameworkDirectory && !string.IsNullOrEmpty(ArchDirectory)) { var archName = Path.Combine(ArchDirectory, Path.GetFileName(fileName)); if (File.Exists(archName)) { fileName = archName; } } var parameters = CreateDefaultReaderParameters(fileName); try { assembly = ModuleDefinition.ReadModule(fileName, parameters).Assembly; params_cache [assembly.Name.ToString()] = parameters; } catch (InvalidOperationException e) { // cecil use the default message so it's not very helpful to detect the root cause if (!e.TargetSite.ToString().Contains("Void ReadSymbols(Mono.Cecil.Cil.ISymbolReader)")) { throw; } parameters.ReadSymbols = false; parameters.SymbolReaderProvider = null; assembly = ModuleDefinition.ReadModule(fileName, parameters).Assembly; // only report the warning (on symbols) if we can actually load the assembly itself (otherwise it's more confusing than helpful) ErrorHelper.Show(ErrorHelper.CreateWarning(129, $"Debugging symbol file for '{fileName}' does not match the assembly and is ignored.")); } } catch (Exception e) { throw new ProductException(9, true, e, "Error while loading assemblies: {0}", fileName); } cache.Add(name, assembly); return(assembly); }
public virtual AssemblyDefinition Load(string fileName) { if (!File.Exists(fileName)) { return(null); } AssemblyDefinition assembly; var name = Path.GetFileNameWithoutExtension(fileName); if (cache.TryGetValue(name, out assembly)) { return(assembly); } try { fileName = Target.GetRealPath(fileName); // Check the architecture-specific directory if (Path.GetDirectoryName(fileName) == FrameworkDirectory && !string.IsNullOrEmpty(ArchDirectory)) { var archName = Path.Combine(ArchDirectory, Path.GetFileName(fileName)); if (File.Exists(archName)) { fileName = archName; } } var parameters = CreateDefaultReaderParameters(fileName); try { assembly = ModuleDefinition.ReadModule(fileName, parameters).Assembly; params_cache [assembly.Name.ToString()] = parameters; } catch (SymbolsNotMatchingException) { parameters.ReadSymbols = false; parameters.SymbolReaderProvider = null; assembly = ModuleDefinition.ReadModule(fileName, parameters).Assembly; // only report the warning (on symbols) if we can actually load the assembly itself (otherwise it's more confusing than helpful) ErrorHelper.Show(ErrorHelper.CreateWarning(129, Errors.MX0129, fileName)); } } catch (Exception e) { throw new ProductException(9, true, e, Errors.MX0009, fileName); } cache.Add(name, assembly); return(assembly); }