diff options
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r-- | src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs | 16 | ||||
-rw-r--r-- | src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 27 |
2 files changed, 31 insertions, 12 deletions
diff --git a/src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs b/src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs index b3415609..8e2f5ef3 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs @@ -21,13 +21,13 @@ namespace StardewModdingAPI.Framework.ModLoading public void Add(params AssemblyDefinition[] assemblies) { foreach (AssemblyDefinition assembly in assemblies) - this.Add(assembly, assembly.Name.Name, assembly.Name.FullName); + this.AddWithExplicitNames(assembly, assembly.Name.Name, assembly.Name.FullName); } - /// <summary>Add known assemblies to the resolver.</summary> + /// <summary>Add a known assembly to the resolver with the given names. This overrides the assembly names that would normally be assigned.</summary> /// <param name="assembly">The assembly to add.</param> /// <param name="names">The assembly names for which it should be returned.</param> - public void Add(AssemblyDefinition assembly, params string[] names) + public void AddWithExplicitNames(AssemblyDefinition assembly, params string[] names) { this.RegisterAssembly(assembly); foreach (string name in names) @@ -36,12 +36,18 @@ namespace StardewModdingAPI.Framework.ModLoading /// <summary>Resolve an assembly reference.</summary> /// <param name="name">The assembly name.</param> - public override AssemblyDefinition Resolve(AssemblyNameReference name) => this.ResolveName(name.Name) ?? base.Resolve(name); + public override AssemblyDefinition Resolve(AssemblyNameReference name) + { + return this.ResolveName(name.Name) ?? base.Resolve(name); + } /// <summary>Resolve an assembly reference.</summary> /// <param name="name">The assembly name.</param> /// <param name="parameters">The assembly reader parameters.</param> - public override AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) => this.ResolveName(name.Name) ?? base.Resolve(name, parameters); + public override AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) + { + return this.ResolveName(name.Name) ?? base.Resolve(name, parameters); + } /********* diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs index e1ad9d37..3e35c9dd 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs @@ -233,15 +233,28 @@ namespace StardewModdingAPI.Framework.ModLoading if (!file.Exists) yield break; // not a local assembly - // read assembly and symbols - byte[] assemblyBytes = File.ReadAllBytes(file.FullName); - Stream readStream = this.TrackForDisposal(new MemoryStream(assemblyBytes)); + // read assembly + AssemblyDefinition assembly; { - FileInfo symbolsFile = new FileInfo(Path.Combine(Path.GetDirectoryName(file.FullName)!, Path.GetFileNameWithoutExtension(file.FullName)) + ".pdb"); - if (symbolsFile.Exists) - this.SymbolReaderProvider.TryAddSymbolData(file.Name, () => this.TrackForDisposal(symbolsFile.OpenRead())); + byte[] assemblyBytes = File.ReadAllBytes(file.FullName); + Stream readStream = this.TrackForDisposal(new MemoryStream(assemblyBytes)); + + try + { + // read assembly with symbols + FileInfo symbolsFile = new FileInfo(Path.Combine(Path.GetDirectoryName(file.FullName)!, Path.GetFileNameWithoutExtension(file.FullName)) + ".pdb"); + if (symbolsFile.Exists) + this.SymbolReaderProvider.TryAddSymbolData(file.Name, () => this.TrackForDisposal(symbolsFile.OpenRead())); + assembly = this.TrackForDisposal(AssemblyDefinition.ReadAssembly(readStream, new ReaderParameters(ReadingMode.Immediate) { AssemblyResolver = assemblyResolver, InMemory = true, ReadSymbols = true, SymbolReaderProvider = this.SymbolReaderProvider })); + } + catch (SymbolsNotMatchingException ex) + { + // read assembly without symbols + this.Monitor.Log($" Failed loading PDB for '{file.Name}'. Technical details:\n{ex}"); + readStream.Position = 0; + assembly = this.TrackForDisposal(AssemblyDefinition.ReadAssembly(readStream, new ReaderParameters(ReadingMode.Immediate) { AssemblyResolver = assemblyResolver, InMemory = true })); + } } - AssemblyDefinition assembly = this.TrackForDisposal(AssemblyDefinition.ReadAssembly(readStream, new ReaderParameters(ReadingMode.Immediate) { AssemblyResolver = assemblyResolver, InMemory = true, ReadSymbols = true, SymbolReaderProvider = this.SymbolReaderProvider })); // skip if already visited if (visitedAssemblyNames.Contains(assembly.Name.Name)) |