Skip to content

Commit 2d478af

Browse files
feat(UI): Use AssemblyWarning when AssemblyReference load faulted
Allow you to easily and quickly see the reference libraries not found fixes #2932
1 parent 971836d commit 2d478af

File tree

4 files changed

+116
-9
lines changed

4 files changed

+116
-9
lines changed

ILSpy/Images/AssemblyLoading.svg

+49
Loading

ILSpy/Images/AssemblyLoading.xaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" ?>
2+
<DrawingGroup xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
3+
<DrawingGroup.ClipGeometry>
4+
<RectangleGeometry Rect="0.0,0.0,16.0,16.0"/>
5+
</DrawingGroup.ClipGeometry>
6+
<GeometryDrawing Brush="#fff6f6f6">
7+
<GeometryDrawing.Geometry>
8+
<PathGeometry Figures="M 16 3 v 9 H 8 V 9 H 6 v 2 H 0 V 4 h 6 v 2 h 2 V 3 h 8 z" FillRule="Nonzero"/>
9+
</GeometryDrawing.Geometry>
10+
</GeometryDrawing>
11+
<GeometryDrawing Brush="#ff424242">
12+
<GeometryDrawing.Geometry>
13+
<PathGeometry Figures="M 1 5 h 4 v 5 H 1 z M 9 4 h 6 v 7 H 9 z M 6 7 h 2 v 1 H 6 z" FillRule="Nonzero"/>
14+
</GeometryDrawing.Geometry>
15+
</GeometryDrawing>
16+
<GeometryDrawing Brush="#fff6f6f6">
17+
<GeometryDrawing.Geometry>
18+
<PathGeometry Figures="m 16 12 c 0 2.2055 -1.7945 4 -4 4 C 9.7945 16 8 14.2055 8 12 A 3.995 3.995 0 0 1 8.544 10 H 8 v -2 H 12 V 12 h -2 c 0 1.103 0.896999 2 2 2 c 1.103 0 2 -0.897 2 -2 c 0 -0.672 -0.3345 -1.295 -0.895 -1.667 l -0.4165 -0.277 l 1.1075 -1.666 l 0.4165 0.2765 A 3.996 3.996 0 0 1 16 12 Z" FillRule="Nonzero"/>
19+
</GeometryDrawing.Geometry>
20+
</GeometryDrawing>
21+
<DrawingGroup Transform="0.49999992,0.0,0.0,0.49999992,8.000001,8.000001">
22+
<GeometryDrawing Brush="#ff00539c">
23+
<GeometryDrawing.Geometry>
24+
<PathGeometry Figures="m 15 8 c 0 3.859 -3.141 7 -7 7 C 4.14 15 1 11.859 1 8 A 7 7 0 0 1 3.12 3 H 1 V 1 H 7 V 7 H 5 V 4.002 A 5.01 5.01 0 0 0 3 8 c 0 2.757 2.243 5 5 5 c 2.757 0 5 -2.243 5 -5 A 4.993 4.993 0 0 0 10.764 3.833 L 11.871 2.167 A 6.989 6.989 0 0 1 15 8 Z" FillRule="Nonzero"/>
25+
</GeometryDrawing.Geometry>
26+
</GeometryDrawing>
27+
</DrawingGroup>
28+
</DrawingGroup>

ILSpy/Images/Images.cs

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static ImageSource Load(string icon)
5151

5252
public static readonly ImageSource Assembly = Load("Assembly");
5353
public static readonly ImageSource AssemblyWarning = Load("AssemblyWarning");
54+
public static readonly ImageSource AssemblyLoading = Load(nameof(AssemblyLoading));
5455
public static readonly ImageSource FindAssembly = Load("FindAssembly");
5556

5657
public static readonly ImageSource Library = Load("Library");

ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs

+38-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
2-
//
2+
//
33
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
44
// software and associated documentation files (the "Software"), to deal in the Software
55
// without restriction, including without limitation the rights to use, copy, modify, merge,
66
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
77
// to whom the Software is furnished to do so, subject to the following conditions:
8-
//
8+
//
99
// The above copyright notice and this permission notice shall be included in all copies or
1010
// substantial portions of the Software.
11-
//
11+
//
1212
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
1313
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
1414
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
@@ -30,9 +30,18 @@ namespace ICSharpCode.ILSpy.TreeNodes
3030
/// </summary>
3131
public sealed class AssemblyReferenceTreeNode : ILSpyTreeNode
3232
{
33+
private enum LoadState
34+
{
35+
Unloaded,
36+
Loading,
37+
Loadded,
38+
Failed
39+
}
3340
readonly MetadataModule module;
3441
readonly AssemblyReference r;
3542
readonly AssemblyTreeNode parentAssembly;
43+
MetadataFile referencedModule;
44+
private LoadState state;
3645

3746
public AssemblyReferenceTreeNode(MetadataModule module, AssemblyReference r, AssemblyTreeNode parentAssembly)
3847
{
@@ -48,7 +57,27 @@ public override object Text {
4857
get { return Language.EscapeName(r.Name) + GetSuffixString(r.Handle); }
4958
}
5059

51-
public override object Icon => Images.Assembly;
60+
public override object Icon {
61+
get {
62+
if (state == LoadState.Unloaded)
63+
{
64+
state = LoadState.Loading;
65+
Dispatcher.CurrentDispatcher.BeginInvoke(() => {
66+
var resolver = parentAssembly.LoadedAssembly.GetAssemblyResolver(MainWindow.Instance.CurrentDecompilerSettings.AutoLoadAssemblyReferences);
67+
referencedModule = resolver.Resolve(r);
68+
state = referencedModule is null
69+
? LoadState.Failed
70+
: LoadState.Loadded;
71+
RaisePropertyChanged(nameof(Icon));
72+
}, DispatcherPriority.Background);
73+
}
74+
return state switch {
75+
LoadState.Loadded => Images.Assembly,
76+
LoadState.Failed => Images.AssemblyWarning,
77+
_ => Images.AssemblyLoading,
78+
};
79+
}
80+
}
5281

5382
public override bool ShowExpander {
5483
get {
@@ -60,7 +89,7 @@ public override bool ShowExpander {
6089
// while the list of references is updated causes problems with WPF's ListView rendering.
6190
// Moving the assembly resolving out of the "add assembly reference"-loop by using the
6291
// dispatcher fixes the issue.
63-
Dispatcher.CurrentDispatcher.BeginInvoke((Action)EnsureLazyChildren, DispatcherPriority.Normal);
92+
Dispatcher.CurrentDispatcher.BeginInvoke(EnsureLazyChildren, DispatcherPriority.Normal);
6493
}
6594
return base.ShowExpander;
6695
}
@@ -79,10 +108,7 @@ public override void ActivateItem(System.Windows.RoutedEventArgs e)
79108
protected override void LoadChildren()
80109
{
81110
this.Children.Add(new AssemblyReferenceReferencedTypesTreeNode(module, r));
82-
83-
var resolver = parentAssembly.LoadedAssembly.GetAssemblyResolver(MainWindow.Instance.CurrentDecompilerSettings.AutoLoadAssemblyReferences);
84-
var referencedModule = resolver.Resolve(r);
85-
if (referencedModule != null)
111+
if (referencedModule is not null)
86112
{
87113
var module = (MetadataModule)referencedModule.GetTypeSystemWithCurrentOptionsOrNull().MainModule;
88114
foreach (var childRef in referencedModule.AssemblyReferences)
@@ -106,7 +132,10 @@ public override void Decompile(Language language, ITextOutput output, Decompilat
106132
output.Indent();
107133
language.WriteCommentLine(output, "Assembly reference loading information:");
108134
if (info.HasErrors)
135+
{
109136
language.WriteCommentLine(output, "There were some problems during assembly reference load, see below for more information!");
137+
state = LoadState.Failed;
138+
}
110139
foreach (var item in info.Messages)
111140
{
112141
language.WriteCommentLine(output, $"{item.Item1}: {item.Item2}");

0 commit comments

Comments
 (0)