Permalink
Browse files

Fix #1014: fix assembly load errors causing ILSpy to crash

  • Loading branch information...
dgrunwald committed Dec 19, 2017
1 parent 871f28c commit d18b4c2a1faddf2a8f4130e4ea13cd8cf80ddc99
View
@@ -273,7 +273,7 @@ void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args)
}
} else {
foreach (LoadedAssembly asm in commandLineLoadedAssemblies) {
ModuleDefinition def = asm.GetModuleDefinitionAsync().Result;
ModuleDefinition def = asm.GetModuleDefinitionOrNull();
if (def != null) {
MemberReference mr = XmlDocKeyProvider.FindMemberByKey(def, args.NavigateTo);
if (mr != null) {
@@ -292,7 +292,7 @@ void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args)
} else if (commandLineLoadedAssemblies.Count == 1) {
// NavigateTo == null and an assembly was given on the command-line:
// Select the newly loaded assembly
JumpToReference(commandLineLoadedAssemblies[0].GetModuleDefinitionAsync().Result);
JumpToReference(commandLineLoadedAssemblies[0].GetModuleDefinitionOrNull());
}
if (args.Search != null)
{
View
@@ -216,7 +216,7 @@ public void Run()
try {
var searcher = GetSearchStrategy(searchMode, searchTerm);
foreach (var loadedAssembly in assemblies) {
ModuleDefinition module = loadedAssembly.GetModuleDefinitionAsync().Result;
ModuleDefinition module = loadedAssembly.GetModuleDefinitionOrNull();
if (module == null)
continue;
CancellationToken cancellationToken = cts.Token;
@@ -38,7 +38,7 @@ public override void ActivateItem(System.Windows.RoutedEventArgs e)
public override bool HandleAssemblyListChanged(ICollection<LoadedAssembly> removedAssemblies, ICollection<LoadedAssembly> addedAssemblies)
{
foreach (LoadedAssembly asm in removedAssemblies) {
if (this.Member.Module == asm.GetModuleDefinitionAsync().Result)
if (this.Member.Module == asm.GetModuleDefinitionOrNull())
return false; // remove this node
}
this.Children.RemoveAll(
@@ -185,7 +185,7 @@ public AssemblyTreeNode FindAssemblyNode(ModuleDefinition module)
return null;
App.Current.Dispatcher.VerifyAccess();
foreach (AssemblyTreeNode node in this.Children) {
if (node.LoadedAssembly.IsLoaded && node.LoadedAssembly.GetModuleDefinitionAsync().Result == module)
if (node.LoadedAssembly.IsLoaded && node.LoadedAssembly.GetModuleDefinitionOrNull() == module)
return node;
}
return null;
@@ -77,7 +77,7 @@ protected override void LoadChildren()
if (assemblyListNode != null) {
var refNode = assemblyListNode.FindAssemblyNode(parentAssembly.LoadedAssembly.LookupReferencedAssembly(r));
if (refNode != null) {
ModuleDefinition module = refNode.LoadedAssembly.GetModuleDefinitionAsync().Result;
ModuleDefinition module = refNode.LoadedAssembly.GetModuleDefinitionOrNull();
if (module != null) {
foreach (var childRef in module.AssemblyReferences)
this.Children.Add(new AssemblyReferenceTreeNode(childRef, refNode));
@@ -145,7 +145,7 @@ void OnAssemblyLoaded(Task<ModuleDefinition> moduleTask)
protected override void LoadChildren()
{
ModuleDefinition moduleDefinition = assembly.GetModuleDefinitionAsync().Result;
ModuleDefinition moduleDefinition = assembly.GetModuleDefinitionOrNull();
if (moduleDefinition == null) {
// if we crashed on loading, then we don't have any children
return;
@@ -396,8 +396,9 @@ public void Execute(TextViewContext context)
return;
foreach (var node in context.SelectedTreeNodes) {
var la = ((AssemblyTreeNode)node).LoadedAssembly;
if (!la.HasLoadError) {
foreach (var assyRef in la.GetModuleDefinitionAsync().Result.AssemblyReferences) {
var module = la.GetModuleDefinitionOrNull();
if (module != null) {
foreach (var assyRef in module.AssemblyReferences) {
la.LookupReferencedAssembly(assyRef);
}
}
@@ -60,7 +60,7 @@ protected override void LoadChildren()
IEnumerable<ILSpyTreeNode> FetchChildren(CancellationToken cancellationToken)
{
// FetchChildren() runs on the main thread; but the enumerator will be consumed on a background thread
var assemblies = list.GetAssemblies().Select(node => node.GetModuleDefinitionAsync().Result).Where(asm => asm != null).ToArray();
var assemblies = list.GetAssemblies().Select(node => node.GetModuleDefinitionOrNull()).Where(asm => asm != null).ToArray();
return FindDerivedTypes(type, assemblies, cancellationToken);
}
@@ -27,7 +27,7 @@ public void Execute(TextViewContext context)
if (context.SelectedTreeNodes == null)
return;
AssemblyTreeNode node = (AssemblyTreeNode)context.SelectedTreeNodes[0];
AssemblyDefinition asm = node.LoadedAssembly.GetAssemblyDefinitionAsync().Result;
AssemblyDefinition asm = node.LoadedAssembly.GetAssemblyDefinitionOrNull();
if (asm != null) {
SaveFileDialog dlg = new SaveFileDialog();
dlg.FileName = node.LoadedAssembly.FileName;

0 comments on commit d18b4c2

Please sign in to comment.