From dbd9632f34db52d84597ef8ce3623b4c9b258f14 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 30 Jul 2024 20:17:32 +0200 Subject: [PATCH 1/3] Fix #3247: InvalidOperationException thrown when reading debug metadata files --- ICSharpCode.Decompiler/Metadata/MetadataFile.cs | 1 + ICSharpCode.Decompiler/Metadata/PEFile.cs | 1 + ICSharpCode.Decompiler/Metadata/WebCilFile.cs | 1 + ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs | 4 ++-- ICSharpCode.ILSpyX/LoadedAssembly.cs | 4 ++-- ILSpy/TreeNodes/AssemblyTreeNode.cs | 11 ++++++++++- 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ICSharpCode.Decompiler/Metadata/MetadataFile.cs b/ICSharpCode.Decompiler/Metadata/MetadataFile.cs index c92c0e061..b8c284027 100644 --- a/ICSharpCode.Decompiler/Metadata/MetadataFile.cs +++ b/ICSharpCode.Decompiler/Metadata/MetadataFile.cs @@ -61,6 +61,7 @@ namespace ICSharpCode.Decompiler.Metadata public virtual int MetadataOffset { get; } public virtual bool IsEmbedded { get; } + public virtual bool IsMetadataOnly { get; } = true; public bool IsAssembly => Metadata.IsAssembly; diff --git a/ICSharpCode.Decompiler/Metadata/PEFile.cs b/ICSharpCode.Decompiler/Metadata/PEFile.cs index 9277ed71f..40e88534d 100644 --- a/ICSharpCode.Decompiler/Metadata/PEFile.cs +++ b/ICSharpCode.Decompiler/Metadata/PEFile.cs @@ -53,6 +53,7 @@ namespace ICSharpCode.Decompiler.Metadata public override bool IsEmbedded => false; public override int MetadataOffset => Reader.PEHeaders.MetadataStartOffset; + public override bool IsMetadataOnly => false; public void Dispose() { diff --git a/ICSharpCode.Decompiler/Metadata/WebCilFile.cs b/ICSharpCode.Decompiler/Metadata/WebCilFile.cs index d862c261b..b93033c32 100644 --- a/ICSharpCode.Decompiler/Metadata/WebCilFile.cs +++ b/ICSharpCode.Decompiler/Metadata/WebCilFile.cs @@ -183,6 +183,7 @@ namespace ICSharpCode.Decompiler.Metadata } public override int MetadataOffset { get; } + public override bool IsMetadataOnly => false; private static int GetContainingSectionIndex(IEnumerable sections, int rva) { diff --git a/ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs b/ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs index 8f01faf0f..290e225bf 100644 --- a/ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs +++ b/ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs @@ -72,7 +72,7 @@ namespace ICSharpCode.ILSpyX.Analyzers { return assemblyListSnapshot.GetAllAssembliesAsync().GetAwaiter().GetResult() .Select(asm => asm.GetMetadataFileOrNull()) - .Where(x => x != null)!; + .Where(x => x != null && !x.IsMetadataOnly)!; } public DecompilerTypeSystem ConstructTypeSystem(MetadataFile module) @@ -207,7 +207,7 @@ namespace ICSharpCode.ILSpyX.Analyzers if (friendAssemblies.Contains(assembly.ShortName)) { var module = assembly.GetMetadataFileOrNull(); - if (module == null) + if (module == null || module.IsMetadataOnly) continue; if (ModuleReferencesScopeType(module.Metadata, typeScope.Name, typeScope.Namespace)) yield return module; diff --git a/ICSharpCode.ILSpyX/LoadedAssembly.cs b/ICSharpCode.ILSpyX/LoadedAssembly.cs index 169012d44..8f7298c84 100644 --- a/ICSharpCode.ILSpyX/LoadedAssembly.cs +++ b/ICSharpCode.ILSpyX/LoadedAssembly.cs @@ -211,7 +211,7 @@ namespace ICSharpCode.ILSpyX { return LazyInitializer.EnsureInitialized(ref this.typeSystem, () => { var module = GetMetadataFileOrNull(); - if (module == null) + if (module == null || module.IsMetadataOnly) return null!; return new SimpleCompilation( module.WithOptions(TypeSystemOptions.Default | TypeSystemOptions.Uncached | TypeSystemOptions.KeepModifiers), @@ -230,7 +230,7 @@ namespace ICSharpCode.ILSpyX if (typeSystemWithOptions != null && options == currentTypeSystemOptions) return typeSystemWithOptions; var module = GetMetadataFileOrNull(); - if (module == null) + if (module == null || module.IsMetadataOnly) return null; currentTypeSystemOptions = options; return typeSystemWithOptions = new SimpleCompilation( diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index 44969d558..2449047c7 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -467,7 +467,16 @@ namespace ICSharpCode.ILSpy.TreeNodes var loadResult = LoadedAssembly.GetLoadResultAsync().GetAwaiter().GetResult(); if (loadResult.MetadataFile != null) { - language.DecompileAssembly(LoadedAssembly, output, options); + switch (loadResult.MetadataFile.Kind) + { + case MetadataFile.MetadataFileKind.ProgramDebugDatabase: + case MetadataFile.MetadataFileKind.Metadata: + output.WriteLine("// " + LoadedAssembly.FileName); + break; + default: + language.DecompileAssembly(LoadedAssembly, output, options); + break; + } } else if (loadResult.Package != null) { From 065e7eca1d477da6cff4aa07c723152f0cc511aa Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 9 Jul 2024 15:12:50 +0200 Subject: [PATCH 2/3] Fix #3227: Only call NewLine() in case no property initializer is present. --- .../CSharp/OutputVisitor/CSharpOutputVisitor.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs b/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs index c929888cf..96d591dab 100644 --- a/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs +++ b/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs @@ -2694,7 +2694,11 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor propertyDeclaration.Initializer.AcceptVisitor(this); Semicolon(); } - NewLine(); + else + { + // The call to Semicolon() above prints a newline too + NewLine(); + } } else { From 7e74de28157e6a39304ae5b50020ffd61f356e12 Mon Sep 17 00:00:00 2001 From: tom-englert Date: Sat, 3 Aug 2024 10:55:49 +0200 Subject: [PATCH 3/3] Fix #3246: Choppy scrolling when scrolling fast after smooth scrolling introduction (#3248) * Fix #3246: Choppy scrolling when scrolling fast after smooth scrolling introduction * Update TomsToolbox to fix AdvancedScrollWheelBehavior and apply to all scroll viewers. * Also activate AdvancedScrollWheelBehavior on the special ZoomScrollViewer --------- Co-authored-by: tom-englert --- Directory.Packages.props | 2 +- ILSpy/App.xaml | 5 ++++- ILSpy/Controls/ZoomScrollViewer.xaml | 4 +++- ILSpy/Metadata/Helpers.cs | 3 +++ ILSpy/Options/DecompilerSettingsPanel.xaml | 2 +- ILSpy/Options/DisplaySettingsPanel.xaml | 2 +- ILSpy/Search/SearchPane.xaml | 4 +++- ILSpy/TextView/DecompilerTextView.xaml | 6 ++---- 8 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 6d1e81e99..41b329b4a 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -45,7 +45,7 @@ - + \ No newline at end of file diff --git a/ILSpy/App.xaml b/ILSpy/App.xaml index 151558268..0cfda48ce 100644 --- a/ILSpy/App.xaml +++ b/ILSpy/App.xaml @@ -3,7 +3,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:styles="urn:TomsToolbox.Wpf.Styles" xmlns:toms="urn:TomsToolbox" - xmlns:ilSpy="clr-namespace:ICSharpCode.ILSpy" xmlns:themes="clr-namespace:ICSharpCode.ILSpy.Themes" StartupUri="MainWindow.xaml"> @@ -25,5 +24,9 @@ + + \ No newline at end of file diff --git a/ILSpy/Controls/ZoomScrollViewer.xaml b/ILSpy/Controls/ZoomScrollViewer.xaml index 4c72e7eab..509b8d636 100644 --- a/ILSpy/Controls/ZoomScrollViewer.xaml +++ b/ILSpy/Controls/ZoomScrollViewer.xaml @@ -1,8 +1,10 @@  + xmlns:Controls="clr-namespace:ICSharpCode.ILSpy.Controls" + xmlns:toms="urn:TomsToolbox">