From 4b64849e84816aed5826d35504aae90e38ee685f Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Mon, 5 Oct 2026 15:37:32 +0200 Subject: [PATCH 1/4] Give docks capability overrides so Dock's chrome bindings resolve Dock's theme binds DockCapabilityOverrides.CanDrag/CanDrop on the tool and document docks themselves, not only on the panes inside them, and logged a binding error per property at startup. Filling them in from InitLayout covers layouts restored from disk, which never pass through CreateLayout. Assisted-by: Claude:claude-fable-5-1:Claude Code --- ILSpy/Docking/ILSpyDockFactory.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ILSpy/Docking/ILSpyDockFactory.cs b/ILSpy/Docking/ILSpyDockFactory.cs index f275e71a6b4..86d650f4ae6 100644 --- a/ILSpy/Docking/ILSpyDockFactory.cs +++ b/ILSpy/Docking/ILSpyDockFactory.cs @@ -199,6 +199,12 @@ public override void InitLayout(IDockable layout) if (layout is IRootDock { Id: { Length: > 0 } rootId } root) DockableLocator[rootId] = () => root; + // Dock's theme template binds against DockCapabilityOverrides.{CanDrag, CanDrop} on + // every dockable, the docks included. A layout restored from disk carries none, so + // fill them in here, where both fresh and restored layouts pass through. + foreach (var dockable in Flatten(layout)) + dockable.DockCapabilityOverrides ??= new DockCapabilityOverrides(); + base.InitLayout(layout); } @@ -527,6 +533,7 @@ public void ActivateAndFocus(IDock owner, IDockable dockable) Alignment = dockAlignment, VisibleDockables = CreateList(System.Array.Empty()), DockCapabilityPolicy = new DockCapabilityPolicy(), + DockCapabilityOverrides = new DockCapabilityOverrides(), }; switch (alignment) From a27a6ed9a8f268f66674c470abbf274af6d465d6 Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Mon, 5 Oct 2026 15:37:40 +0200 Subject: [PATCH 2/4] Host the update banner through a content template With a DataContext binding of its own the panel first inherited the main window's view model, and each of its compiled bindings failed the cast to UpdatePanelViewModel and logged an error at startup. The new test boots the window with a capturing log sink and fails on any binding error. Assisted-by: Claude:claude-fable-5-1:Claude Code --- .../MainWindow/StartupBindingErrorTests.cs | 75 +++++++++++++++++++ ILSpy/Views/MainWindow.axaml | 11 ++- 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 ILSpy.Tests/MainWindow/StartupBindingErrorTests.cs diff --git a/ILSpy.Tests/MainWindow/StartupBindingErrorTests.cs b/ILSpy.Tests/MainWindow/StartupBindingErrorTests.cs new file mode 100644 index 00000000000..bd55fc565cf --- /dev/null +++ b/ILSpy.Tests/MainWindow/StartupBindingErrorTests.cs @@ -0,0 +1,75 @@ +// Copyright (c) 2026 Christoph Wille +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + + +using System.Collections.Generic; +using System.Threading.Tasks; + +using Avalonia.Headless.NUnit; +using Avalonia.Logging; + +using AwesomeAssertions; + +using NUnit.Framework; + +namespace ICSharpCode.ILSpy.Tests; + +/// +/// A binding that fails while the main window comes up is logged by Avalonia and otherwise +/// goes unnoticed: the bound property silently keeps its default. Booting the window with a +/// capturing log sink pins that startup produces no such errors. +/// +[TestFixture] +public class StartupBindingErrorTests +{ + sealed class BindingErrorSink(ILogSink? inner) : ILogSink + { + public List Errors { get; } = new(); + + public bool IsEnabled(LogEventLevel level, string area) + => area == LogArea.Binding || (inner?.IsEnabled(level, area) ?? false); + + public void Log(LogEventLevel level, string area, object? source, string messageTemplate) + => Log(level, area, source, messageTemplate, []); + + public void Log(LogEventLevel level, string area, object? source, string messageTemplate, params object?[] propertyValues) + { + if (area == LogArea.Binding && level >= LogEventLevel.Warning) + Errors.Add($"{messageTemplate} [{string.Join(", ", propertyValues)}] ({source})"); + } + } + + [AvaloniaTest] + public async Task Booting_The_Main_Window_Logs_No_Binding_Errors() + { + var previous = Logger.Sink; + var sink = new BindingErrorSink(previous); + Logger.Sink = sink; + try + { + await TestHarness.BootAsync(); + await Waiters.WaitForIdleAsync(); + } + finally + { + Logger.Sink = previous; + } + + sink.Errors.Should().BeEmpty("every binding in the startup UI must resolve against its data context"); + } +} diff --git a/ILSpy/Views/MainWindow.axaml b/ILSpy/Views/MainWindow.axaml index f65eb5d8056..e2add2c8fae 100644 --- a/ILSpy/Views/MainWindow.axaml +++ b/ILSpy/Views/MainWindow.axaml @@ -42,7 +42,16 @@ - + + + + + + + + From 772085f264e5454996b57f909b51cd43422efc4c Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Mon, 5 Oct 2026 15:37:46 +0200 Subject: [PATCH 3/4] Let tree rows inherit ShowLines instead of binding to an ancestor The ancestor binding logged 'Ancestor not found' whenever a row's content was evaluated outside a SharpTreeView. An inherited property needs no lookup, and leaves the lines on where there is no tree view at all. Assisted-by: Claude:claude-fable-5-1:Claude Code --- ILSpy.Tests/Controls/SharpTreeViewTests.cs | 15 +++++++++++++++ ILSpy/Controls/TreeLines.cs | 12 ++++++++++-- ILSpy/Controls/TreeView/SharpTreeView.axaml | 3 +-- ILSpy/Controls/TreeView/SharpTreeView.cs | 2 +- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/ILSpy.Tests/Controls/SharpTreeViewTests.cs b/ILSpy.Tests/Controls/SharpTreeViewTests.cs index 32aabfc6b71..4f699490b5f 100644 --- a/ILSpy.Tests/Controls/SharpTreeViewTests.cs +++ b/ILSpy.Tests/Controls/SharpTreeViewTests.cs @@ -32,6 +32,7 @@ using ICSharpCode.ILSpyX.TreeView; +using ICSharpCode.ILSpy.Controls; using ICSharpCode.ILSpy.Controls.TreeView; using NUnit.Framework; @@ -65,6 +66,20 @@ public TestNode(string text, params TestNode[] children) return (window, tree, root); } + [AvaloniaTest] + public void ShowLines_Reaches_The_Connector_Lines_Of_Every_Row() + { + var (_, tree, _) = Host(); + var lines = tree.GetVisualDescendants().OfType().ToList(); + lines.Should().NotBeEmpty("every realized row carries a TreeLines"); + lines.Should().OnlyContain(l => l.GetValue(TreeLines.ShowLinesProperty), "lines are shown by default"); + + tree.ShowLines = false; + + lines.Should().OnlyContain(l => !l.GetValue(TreeLines.ShowLinesProperty), + "the rows take the setting from the tree view they are in"); + } + [AvaloniaTest] public void Flattens_Visible_Nodes_And_Expand_Collapse_Updates_Row_Count() { diff --git a/ILSpy/Controls/TreeLines.cs b/ILSpy/Controls/TreeLines.cs index 9ef34a303c5..7801a61d0c1 100644 --- a/ILSpy/Controls/TreeLines.cs +++ b/ILSpy/Controls/TreeLines.cs @@ -22,6 +22,7 @@ using Avalonia.Controls; using Avalonia.Media; +using ICSharpCode.ILSpy.Controls.TreeView; using ICSharpCode.ILSpyX.TreeView; namespace ICSharpCode.ILSpy.Controls @@ -48,12 +49,19 @@ public class TreeLines : Control public static readonly StyledProperty LevelProperty = AvaloniaProperty.Register(nameof(Level)); + /// + /// Inherited from the hosting ; stays at its default (lines + /// shown) where there is none. + /// + public static readonly StyledProperty ShowLinesProperty = + SharpTreeView.ShowLinesProperty.AddOwner(); + static TreeLines() { // Classic Windows-Explorer dotted connector lines. var pen = new Pen(Brushes.Gray, 1) { DashStyle = new DashStyle(new double[] { 1, 1 }, 0) }; Pen = pen.ToImmutable(); - AffectsRender(NodeProperty, LevelProperty); + AffectsRender(NodeProperty, LevelProperty, ShowLinesProperty); IsHitTestVisibleProperty.OverrideDefaultValue(false); } @@ -73,7 +81,7 @@ public int Level { public override void Render(DrawingContext context) { var node = Node; - if (node == null || node.IsRoot) + if (node == null || node.IsRoot || !GetValue(ShowLinesProperty)) return; double height = Bounds.Height; diff --git a/ILSpy/Controls/TreeView/SharpTreeView.axaml b/ILSpy/Controls/TreeView/SharpTreeView.axaml index 692b4c2fb84..4c03a66ad85 100644 --- a/ILSpy/Controls/TreeView/SharpTreeView.axaml +++ b/ILSpy/Controls/TreeView/SharpTreeView.axaml @@ -94,8 +94,7 @@ - + diff --git a/ILSpy/Controls/TreeView/SharpTreeView.cs b/ILSpy/Controls/TreeView/SharpTreeView.cs index 844f2cd35e3..a4cc9830d5a 100644 --- a/ILSpy/Controls/TreeView/SharpTreeView.cs +++ b/ILSpy/Controls/TreeView/SharpTreeView.cs @@ -56,7 +56,7 @@ public class SharpTreeView : ListBox AvaloniaProperty.Register(nameof(ShowRootExpander), defaultValue: false); public static readonly StyledProperty ShowLinesProperty = - AvaloniaProperty.Register(nameof(ShowLines), defaultValue: true); + AvaloniaProperty.Register(nameof(ShowLines), defaultValue: true, inherits: true); TreeFlattener? flattener; string searchBuffer = string.Empty; From fabd0de38e46de3a7b0a794bcf241fded02f81a2 Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Mon, 5 Oct 2026 15:37:53 +0200 Subject: [PATCH 4/4] Keep the background load sweep going past unloadable assemblies One assembly that failed to load faulted the whole sweep, which skipped the command requery at its end. 'Remove assemblies with load errors' was therefore not re-evaluated in the one case it exists for. ShowAssemblyList(AssemblyList) is internal so the test can show a list whose load it controls. Assisted-by: Claude:claude-fable-5-1:Claude Code --- .../AssemblyTree/BackgroundLoadSweepTests.cs | 102 ++++++++++++++++++ ILSpy/AssemblyTree/AssemblyTreeModel.cs | 7 +- 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 ILSpy.Tests/AssemblyTree/BackgroundLoadSweepTests.cs diff --git a/ILSpy.Tests/AssemblyTree/BackgroundLoadSweepTests.cs b/ILSpy.Tests/AssemblyTree/BackgroundLoadSweepTests.cs new file mode 100644 index 00000000000..ea4b75b3794 --- /dev/null +++ b/ILSpy.Tests/AssemblyTree/BackgroundLoadSweepTests.cs @@ -0,0 +1,102 @@ +// Copyright (c) 2026 Christoph Wille +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + + +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +using Avalonia.Headless.NUnit; +using Avalonia.Threading; + +using ICSharpCode.ILSpy.AppEnv; + +using NUnit.Framework; + +namespace ICSharpCode.ILSpy.Tests.AssemblyTree; + +/// +/// The background sweep that loads every assembly of the shown list ends by asking the commands +/// to re-evaluate, which is what enables "Remove assemblies with load errors". That has to happen +/// when one of the assemblies fails to load, since that is the only case the command is for. +/// +[TestFixture] +public class BackgroundLoadSweepTests +{ + /// + /// Holds a load open until the test lets go of it, then ends without a single byte, which + /// no loader accepts. The test thereby chooses the moment the assembly fails to load. + /// + sealed class GatedEmptyStream : Stream + { + public ManualResetEventSlim Gate { get; } = new(); + + public override bool CanRead => true; + public override bool CanSeek => false; + public override bool CanWrite => false; + public override long Length => throw new NotSupportedException(); + public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } + + public override int Read(byte[] buffer, int offset, int count) + { + Gate.Wait(); + return 0; + } + + public override void Flush() { } + public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); + public override void SetLength(long value) => throw new NotSupportedException(); + public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException(); + } + + [AvaloniaTest] + public async Task Sweep_Requeries_Commands_When_An_Assembly_Fails_To_Load() + { + var (_, vm) = await TestHarness.BootAsync(); + await Waiters.WaitForIdleAsync(); + + // Show a list whose only assembly cannot finish loading before the gate opens, and let + // everything the switch itself queues run first, so that a requery seen afterwards can + // only be the one that ends the sweep. + var stream = new GatedEmptyStream(); + var listManager = AppComposition.Current.GetExport().AssemblyListManager; + var list = listManager.CreateList("gated-list"); + var assembly = list.OpenAssembly(Path.Combine(Path.GetTempPath(), "ILSpyGated.dll"), stream); + vm.AssemblyTreeModel.ShowAssemblyList(list); + await Waiters.WaitForAsync( + () => !Dispatcher.UIThread.HasJobsWithPriority(DispatcherPriority.Background), + description: "the list switch to settle"); + + bool requeried = false; + EventHandler onRequery = (_, _) => requeried = true; + ICSharpCode.ILSpy.Commands.CommandManager.AddRequerySuggested(onRequery); + try + { + stream.Gate.Set(); + await Waiters.WaitForAsync(() => assembly.HasLoadError, description: "the gated assembly to fail loading"); + await Waiters.WaitForAsync(() => requeried, + description: "a command requery after the assembly failed to load"); + } + finally + { + stream.Gate.Set(); + ICSharpCode.ILSpy.Commands.CommandManager.RemoveRequerySuggested(onRequery); + } + } +} diff --git a/ILSpy/AssemblyTree/AssemblyTreeModel.cs b/ILSpy/AssemblyTree/AssemblyTreeModel.cs index b3ffa70c804..4f1a2a14ae1 100644 --- a/ILSpy/AssemblyTree/AssemblyTreeModel.cs +++ b/ILSpy/AssemblyTree/AssemblyTreeModel.cs @@ -557,7 +557,7 @@ void ShowAssemblyList(string name) ShowAssemblyList(list); } - void ShowAssemblyList(AssemblyList list) + internal void ShowAssemblyList(AssemblyList list) { using var _ = AppEnv.AppLog.Phase("ShowAssemblyList(list)"); // Detach the previous list's collection-changed wiring so the MessageBus @@ -631,6 +631,11 @@ void ScheduleBackgroundLoadSweep(AssemblyList list) loadTasks.Add(Task.Run(async () => { try { await assembly.GetLoadResultAsync().ConfigureAwait(false); } + catch (Exception) + { + // A file that cannot be loaded is an expected outcome, recorded on the + // LoadedAssembly itself (HasLoadError). It must not fault the sweep. + } finally { throttle.Release(); } }));