From 3b93d095ecd086a0773cc192f545acaa5205ae4d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 6 May 2019 00:43:22 +0200 Subject: [PATCH] Fix #1509: Show error message that unresolved entities cannot be analyzed. --- ILSpy/Analyzers/AnalyzerSearchTreeNode.cs | 4 +--- ILSpy/Analyzers/AnalyzerTreeView.cs | 5 +++++ ILSpy/Properties/Resources.Designer.cs | 13 +++++++++++-- ILSpy/Properties/Resources.resx | 3 +++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs b/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs index 1e020328f..a49051aba 100644 --- a/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs +++ b/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs @@ -52,9 +52,7 @@ namespace ICSharpCode.ILSpy.Analyzers protected IEnumerable FetchChildren(CancellationToken ct) { - if (symbol is IEntity entity) { - var module = entity.ParentModule.PEFile; - var ts = new DecompilerTypeSystem(module, module.GetAssemblyResolver()); + if (symbol is IEntity) { var context = new AnalyzerContext() { CancellationToken = ct, Language = Language, diff --git a/ILSpy/Analyzers/AnalyzerTreeView.cs b/ILSpy/Analyzers/AnalyzerTreeView.cs index 2a399b37f..54256935e 100644 --- a/ILSpy/Analyzers/AnalyzerTreeView.cs +++ b/ILSpy/Analyzers/AnalyzerTreeView.cs @@ -109,6 +109,11 @@ namespace ICSharpCode.ILSpy.Analyzers throw new ArgumentNullException(nameof(entity)); } + if (entity.MetadataToken.IsNil) { + MessageBox.Show(Properties.Resources.CannotAnalyzeMissingRef, "ILSpy"); + return; + } + switch (entity) { case ITypeDefinition td: ShowOrFocus(new AnalyzedTypeTreeNode(td)); diff --git a/ILSpy/Properties/Resources.Designer.cs b/ILSpy/Properties/Resources.Designer.cs index 2cb764c53..5c86e06e2 100644 --- a/ILSpy/Properties/Resources.Designer.cs +++ b/ILSpy/Properties/Resources.Designer.cs @@ -330,6 +330,15 @@ namespace ICSharpCode.ILSpy.Properties { } } + /// + /// Looks up a localized string similar to Entity could not be resolved. Cannot analyze entities from missing assembly references. Add the missing reference and try again.. + /// + public static string CannotAnalyzeMissingRef { + get { + return ResourceManager.GetString("CannotAnalyzeMissingRef", resourceCulture); + } + } + /// /// Looks up a localized string similar to Check again. /// @@ -1476,7 +1485,7 @@ namespace ICSharpCode.ILSpy.Properties { } /// - /// 查找类似 Search MSDN... 的本地化字符串。 + /// Looks up a localized string similar to Search MSDN.... /// public static string SearchMSDN { get { @@ -1485,7 +1494,7 @@ namespace ICSharpCode.ILSpy.Properties { } /// - /// Looks up a localized string similar to Search. + /// Looks up a localized string similar to Search. /// public static string SearchPane_Search { get { diff --git a/ILSpy/Properties/Resources.resx b/ILSpy/Properties/Resources.resx index 8d660abf5..0128389d9 100644 --- a/ILSpy/Properties/Resources.resx +++ b/ILSpy/Properties/Resources.resx @@ -726,4 +726,7 @@ Search MSDN... + + Entity could not be resolved. Cannot analyze entities from missing assembly references. Add the missing reference and try again. + \ No newline at end of file