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 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection.Metadata;
using System.Windows; using System.Windows;
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
@ -41,7 +40,7 @@ namespace ICSharpCode.ILSpy.Analyzers
MessageBox.Show(Properties.Resources.CannotAnalyzeMissingRef, "ILSpy"); MessageBox.Show(Properties.Resources.CannotAnalyzeMissingRef, "ILSpy");
return; 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) public override bool HandleAssemblyListChanged(ICollection<LoadedAssembly> removedAssemblies, ICollection<LoadedAssembly> addedAssemblies)

17
ILSpy/EntityReference.cs

@ -15,8 +15,8 @@
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // 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 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
#nullable enable
using System;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection.Metadata; using System.Reflection.Metadata;
@ -27,6 +27,7 @@ namespace ICSharpCode.ILSpy
[DebuggerDisplay("EntityReference Module={Module}, Handle={Handle}, Protocol={Protocol}")] [DebuggerDisplay("EntityReference Module={Module}, Handle={Handle}, Protocol={Protocol}")]
public class EntityReference public class EntityReference
{ {
readonly PEFile? peFile;
public string Module { get; } public string Module { get; }
public Handle Handle { get; } public Handle Handle { get; }
public string Protocol { get; } public string Protocol { get; }
@ -38,15 +39,23 @@ namespace ICSharpCode.ILSpy
this.Protocol = "decompile"; this.Protocol = "decompile";
} }
public EntityReference(string protocol, string moduleFileName, Handle handle) public EntityReference(string? protocol, string moduleFileName, Handle handle)
: this(moduleFileName, handle) : this(moduleFileName, handle)
{ {
this.Protocol = protocol ?? "decompile"; 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;
using System.Reflection.Metadata.Ecma335; using System.Reflection.Metadata.Ecma335;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.Metadata;
@ -37,7 +36,7 @@ namespace ICSharpCode.ILSpy.Commands
public void Execute(TextViewContext context) public void Execute(TextViewContext context)
{ {
int token = GetSelectedToken(context.DataGrid, out PEFile module).Value; 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) public bool IsEnabled(TextViewContext context)

2
ILSpy/TextView/AvalonEditTextOutput.cs

@ -270,7 +270,7 @@ namespace ICSharpCode.ILSpy.TextView
{ {
this.DefinitionLookup.AddDefinition((module, handle), this.TextLength); 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) public void WriteReference(IType type, string text, bool isDefinition = false)

5
ILSpy/TextView/DecompilerTextView.cs

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

Loading…
Cancel
Save