Browse Source

Fix #2402: ArgumentNullException in IL mode for tooltips when decompiling bundle members.

pull/2412/head
Daniel Grunwald 4 years ago
parent
commit
bd700e11a3
  1. 3
      ILSpy/Analyzers/AnalyzerEntityTreeNode.cs
  2. 17
      ILSpy/EntityReference.cs
  3. 3
      ILSpy/Metadata/GoToTokenCommand.cs
  4. 2
      ILSpy/TextView/AvalonEditTextOutput.cs
  5. 5
      ILSpy/TextView/DecompilerTextView.cs

3
ILSpy/Analyzers/AnalyzerEntityTreeNode.cs

@ -17,7 +17,6 @@ @@ -17,7 +17,6 @@
// DEALINGS IN THE SOFTWARE.
using System.Collections.Generic;
using System.Reflection.Metadata;
using System.Windows;
using ICSharpCode.Decompiler.TypeSystem;
@ -41,7 +40,7 @@ namespace ICSharpCode.ILSpy.Analyzers @@ -41,7 +40,7 @@ namespace ICSharpCode.ILSpy.Analyzers
MessageBox.Show(Properties.Resources.CannotAnalyzeMissingRef, "ILSpy");
return;
}
MainWindow.Instance.JumpToReference(new EntityReference(this.Member.ParentModule.PEFile.FileName, this.Member.MetadataToken));
MainWindow.Instance.JumpToReference(new EntityReference(this.Member.ParentModule.PEFile, this.Member.MetadataToken));
}
public override bool HandleAssemblyListChanged(ICollection<LoadedAssembly> removedAssemblies, ICollection<LoadedAssembly> addedAssemblies)

17
ILSpy/EntityReference.cs

@ -15,8 +15,8 @@ @@ -15,8 +15,8 @@
// 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.
#nullable enable
using System;
using System.Diagnostics;
using System.Reflection.Metadata;
@ -27,6 +27,7 @@ namespace ICSharpCode.ILSpy @@ -27,6 +27,7 @@ namespace ICSharpCode.ILSpy
[DebuggerDisplay("EntityReference Module={Module}, Handle={Handle}, Protocol={Protocol}")]
public class EntityReference
{
readonly PEFile? peFile;
public string Module { get; }
public Handle Handle { get; }
public string Protocol { get; }
@ -38,15 +39,23 @@ namespace ICSharpCode.ILSpy @@ -38,15 +39,23 @@ namespace ICSharpCode.ILSpy
this.Protocol = "decompile";
}
public EntityReference(string protocol, string moduleFileName, Handle handle)
public EntityReference(string? protocol, string moduleFileName, Handle handle)
: this(moduleFileName, handle)
{
this.Protocol = protocol ?? "decompile";
}
public PEFile ResolveAssembly(AssemblyList context)
public EntityReference(PEFile module, Handle handle, string protocol = "decompile")
{
return context.FindAssembly(Module)?.GetPEFileOrNull();
this.peFile = module;
this.Module = module.FileName;
this.Handle = handle;
this.Protocol = protocol;
}
public PEFile? ResolveAssembly(AssemblyList context)
{
return peFile ?? context.FindAssembly(Module)?.GetPEFileOrNull();
}
}
}

3
ILSpy/Metadata/GoToTokenCommand.cs

@ -22,7 +22,6 @@ using System.Reflection; @@ -22,7 +22,6 @@ using System.Reflection;
using System.Reflection.Metadata.Ecma335;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.Decompiler.Metadata;
@ -37,7 +36,7 @@ namespace ICSharpCode.ILSpy.Commands @@ -37,7 +36,7 @@ namespace ICSharpCode.ILSpy.Commands
public void Execute(TextViewContext context)
{
int token = GetSelectedToken(context.DataGrid, out PEFile module).Value;
MainWindow.Instance.JumpToReference(new EntityReference("metadata", module.FileName, MetadataTokens.Handle(token)));
MainWindow.Instance.JumpToReference(new EntityReference(module, MetadataTokens.Handle(token), protocol: "metadata"));
}
public bool IsEnabled(TextViewContext context)

2
ILSpy/TextView/AvalonEditTextOutput.cs

@ -270,7 +270,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -270,7 +270,7 @@ namespace ICSharpCode.ILSpy.TextView
{
this.DefinitionLookup.AddDefinition((module, handle), this.TextLength);
}
references.Add(new ReferenceSegment { StartOffset = start, EndOffset = end, Reference = new EntityReference(protocol, module.FileName, handle), IsDefinition = isDefinition });
references.Add(new ReferenceSegment { StartOffset = start, EndOffset = end, Reference = new EntityReference(module, handle, protocol), IsDefinition = isDefinition });
}
public void WriteReference(IType type, string text, bool isDefinition = false)

5
ILSpy/TextView/DecompilerTextView.cs

@ -19,7 +19,6 @@ @@ -19,7 +19,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.IO;
using System.Linq;
@ -49,8 +48,6 @@ using ICSharpCode.Decompiler; @@ -49,8 +48,6 @@ using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.CSharp.OutputVisitor;
using ICSharpCode.Decompiler.CSharp.ProjectDecompiler;
using ICSharpCode.Decompiler.Documentation;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.Output;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.AvalonEdit;
using ICSharpCode.ILSpy.Options;
@ -405,6 +402,8 @@ namespace ICSharpCode.ILSpy.TextView @@ -405,6 +402,8 @@ namespace ICSharpCode.ILSpy.TextView
else if (segment.Reference is EntityReference unresolvedEntity)
{
var module = unresolvedEntity.ResolveAssembly(MainWindow.Instance.CurrentAssemblyList);
if (module == null)
return null;
var typeSystem = new DecompilerTypeSystem(module,
module.GetAssemblyResolver(),
TypeSystemOptions.Default | TypeSystemOptions.Uncached);

Loading…
Cancel
Save