From 213b0dc41eb7a7af8ac21421b065a202bfff8ae2 Mon Sep 17 00:00:00 2001 From: ElektroKill Date: Thu, 12 Oct 2023 20:28:35 +0200 Subject: [PATCH] Add an error dialog when in memory metadata cannot be loaded (refs #249) --- .../DbgLoadModuleReferenceHandlerImpl.cs | 9 ++- ...nSpy.Debugger.DotNet.Resources.Designer.cs | 12 +++- .../dnSpy.Debugger.DotNet.Resources.resx | 59 ++++++++++--------- 3 files changed, 48 insertions(+), 32 deletions(-) diff --git a/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet/Modules/DbgLoadModuleReferenceHandlerImpl.cs b/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet/Modules/DbgLoadModuleReferenceHandlerImpl.cs index ff1f090325..c704d7ee1b 100644 --- a/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet/Modules/DbgLoadModuleReferenceHandlerImpl.cs +++ b/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet/Modules/DbgLoadModuleReferenceHandlerImpl.cs @@ -63,8 +63,11 @@ bool GoToCore(DbgLoadModuleReference moduleRef, ReadOnlyCollection optio loadOptions |= DbgLoadModuleOptions.ForceMemory; bool canShowMessageBox = true; var md = LoadModule(moduleRef.Module, loadOptions, ref canShowMessageBox); - if (md is null) + if (md is null) { + if (canShowMessageBox) + messageBoxService.Value.Show(dnSpy_Debugger_DotNet_Resources.FailedToObtainValidInMemoryMetadataForModule); return false; + } // The file could've been added lazily to the list so add a short delay before we select it bool newTab = options.Any(a => StringComparer.Ordinal.Equals(PredefinedReferenceNavigatorOptions.NewTab, a)); @@ -73,8 +76,10 @@ bool GoToCore(DbgLoadModuleReference moduleRef, ReadOnlyCollection optio } ModuleDef? LoadModule(DbgModule module, DbgLoadModuleOptions options, ref bool canShowMessageBox) { - if (!module.IsDotNetModule()) + if (!module.IsDotNetModule()) { + canShowMessageBox = false; return null; + } if (module.IsDynamic && !module.Runtime.IsClosed && module.Process.IsRunning) { if (canShowMessageBox) { diff --git a/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet/Properties/dnSpy.Debugger.DotNet.Resources.Designer.cs b/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet/Properties/dnSpy.Debugger.DotNet.Resources.Designer.cs index 5225540456..d5f37081dd 100644 --- a/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet/Properties/dnSpy.Debugger.DotNet.Resources.Designer.cs +++ b/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet/Properties/dnSpy.Debugger.DotNet.Resources.Designer.cs @@ -1,7 +1,6 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -132,6 +131,15 @@ public static string DecompilerGeneratedVariablesCanNotBeEvaluated { } } + /// + /// Looks up a localized string similar to Failed to obtain valid in-memory metadata for module!. + /// + public static string FailedToObtainValidInMemoryMetadataForModule { + get { + return ResourceManager.GetString("FailedToObtainValidInMemoryMetadataForModule", resourceCulture); + } + } + /// /// Looks up a localized string similar to IL offset {0}. /// diff --git a/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet/Properties/dnSpy.Debugger.DotNet.Resources.resx b/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet/Properties/dnSpy.Debugger.DotNet.Resources.resx index 57e689f1fa..074537d431 100644 --- a/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet/Properties/dnSpy.Debugger.DotNet.Resources.resx +++ b/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet/Properties/dnSpy.Debugger.DotNet.Resources.resx @@ -1,17 +1,17 @@  - @@ -141,6 +141,9 @@ Decompiler generated variables can't be evaluated + + Failed to obtain valid in-memory metadata for module! + IL offset {0} @@ -186,4 +189,4 @@ Unknown variable or object ID - \ No newline at end of file +