diff --git a/ILSpy/Commands/GeneratePdbContextMenuEntry.cs b/ILSpy/Commands/GeneratePdbContextMenuEntry.cs index 4f803f66f..97101ece0 100644 --- a/ILSpy/Commands/GeneratePdbContextMenuEntry.cs +++ b/ILSpy/Commands/GeneratePdbContextMenuEntry.cs @@ -51,7 +51,7 @@ namespace ICSharpCode.ILSpy { return context.SelectedTreeNodes?.Length == 1 && context.SelectedTreeNodes?.FirstOrDefault() is AssemblyTreeNode tn - && !tn.LoadedAssembly.HasLoadError; + && tn.LoadedAssembly.IsLoadedAsValidAssembly; } internal static void GeneratePdbForAssembly(LoadedAssembly assembly) diff --git a/ILSpy/Commands/Pdb2XmlCommand.cs b/ILSpy/Commands/Pdb2XmlCommand.cs index b261651cc..eada39b20 100644 --- a/ILSpy/Commands/Pdb2XmlCommand.cs +++ b/ILSpy/Commands/Pdb2XmlCommand.cs @@ -83,10 +83,10 @@ namespace ICSharpCode.ILSpy { var selectedNodes = context.SelectedTreeNodes; return selectedNodes?.Any() == true - && selectedNodes.All(n => n is AssemblyTreeNode asm && !asm.LoadedAssembly.HasLoadError); + && selectedNodes.All(n => n is AssemblyTreeNode asm && asm.LoadedAssembly.IsLoadedAsValidAssembly); } } } -#endif \ No newline at end of file +#endif diff --git a/ILSpy/Commands/SaveCodeContextMenuEntry.cs b/ILSpy/Commands/SaveCodeContextMenuEntry.cs index 088ab9da5..0a849f134 100644 --- a/ILSpy/Commands/SaveCodeContextMenuEntry.cs +++ b/ILSpy/Commands/SaveCodeContextMenuEntry.cs @@ -21,7 +21,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows; -using System.Windows.Input; using ICSharpCode.ILSpy.Properties; using ICSharpCode.ILSpy.TreeNodes; @@ -75,7 +74,7 @@ namespace ICSharpCode.ILSpy.TextView { var assemblies = selectedNodes.OfType() .Select(n => n.LoadedAssembly) - .Where(a => !a.HasLoadError).ToArray(); + .Where(a => a.IsLoadedAsValidAssembly).ToArray(); SolutionWriter.CreateSolution(textView, selectedPath, currentLanguage, assemblies); } return; diff --git a/ILSpy/Commands/SelectPdbContextMenuEntry.cs b/ILSpy/Commands/SelectPdbContextMenuEntry.cs index c6977eb51..7f90c6566 100644 --- a/ILSpy/Commands/SelectPdbContextMenuEntry.cs +++ b/ILSpy/Commands/SelectPdbContextMenuEntry.cs @@ -56,7 +56,8 @@ namespace ICSharpCode.ILSpy public bool IsVisible(TextViewContext context) { return context.SelectedTreeNodes?.Length == 1 - && context.SelectedTreeNodes?.FirstOrDefault() is AssemblyTreeNode; + && context.SelectedTreeNodes?.FirstOrDefault() is AssemblyTreeNode asm + && asm.LoadedAssembly.IsLoadedAsValidAssembly; } } } diff --git a/ILSpy/LoadedAssembly.cs b/ILSpy/LoadedAssembly.cs index 070506e3c..4fdcb2975 100644 --- a/ILSpy/LoadedAssembly.cs +++ b/ILSpy/LoadedAssembly.cs @@ -234,8 +234,24 @@ namespace ICSharpCode.ILSpy } } + /// + /// Gets whether loading finished for this file (either successfully or unsuccessfully). + /// public bool IsLoaded => loadingTask.IsCompleted; + /// + /// Gets whether this file was loaded successfully as an assembly (not as a bundle). + /// + public bool IsLoadedAsValidAssembly { + get { + return loadingTask.Status == TaskStatus.RanToCompletion && loadingTask.Result.PEFile != null; + } + } + + /// + /// Gets whether loading failed (file does not exist, unknown file format). + /// Returns false for valid assemblies and valid bundles. + /// public bool HasLoadError => loadingTask.IsFaulted; public bool IsAutoLoaded { get; set; } diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index a53def1e0..40c0f86f7 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -338,6 +338,8 @@ namespace ICSharpCode.ILSpy.TreeNodes public override bool Save(TabPageModel tabPage) { + if (!LoadedAssembly.IsLoadedAsValidAssembly) + return false; Language language = this.Language; if (string.IsNullOrEmpty(language.ProjectFileExtension)) return false; @@ -445,7 +447,7 @@ namespace ICSharpCode.ILSpy.TreeNodes { if (context.SelectedTreeNodes == null) return false; - return context.SelectedTreeNodes.All(n => n is AssemblyTreeNode); + return context.SelectedTreeNodes.All(n => n is AssemblyTreeNode asm && asm.LoadedAssembly.IsLoadedAsValidAssembly); } public bool IsEnabled(TextViewContext context)