Browse Source

add some exception handling for startup and MEF exceptions

pull/348/head
Siegfried Pammer 13 years ago
parent
commit
577f025d5f
  1. 18
      ILSpy/App.xaml.cs
  2. 29
      ILSpy/MainWindow.xaml.cs

18
ILSpy/App.xaml.cs

@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition.Hosting;
using System.Diagnostics;
using System.IO;
@ -26,6 +27,7 @@ using System.Windows;
using System.Windows.Documents;
using System.Windows.Navigation;
using System.Windows.Threading;
using ICSharpCode.ILSpy.Debugger.Services;
using ICSharpCode.ILSpy.TextView;
@ -44,6 +46,14 @@ namespace ICSharpCode.ILSpy
internal static CommandLineArguments CommandLineArguments;
internal static IList<ExceptionData> StartupExceptions = new List<ExceptionData>();
internal class ExceptionData
{
public Exception Exception;
public string PluginName;
}
public App()
{
var cmdArgs = Environment.GetCommandLineArgs().Skip(1);
@ -65,9 +75,13 @@ namespace ICSharpCode.ILSpy
foreach (string plugin in Directory.GetFiles(appPath, "*.Plugin.dll")) {
string shortName = Path.GetFileNameWithoutExtension(plugin);
try {
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.Load(shortName)));
var asm = Assembly.Load(shortName);
asm.GetTypes();
catalog.Catalogs.Add(new AssemblyCatalog(asm));
} catch (Exception ex) {
MessageBox.Show(ex.ToString(), "Error loading plugin " + shortName);
// Cannot show MessageBox here, because WPF would crash with a XamlParseException
// Remember and show exceptions in text output, once MainWindow is properly initialized
StartupExceptions.Add(new ExceptionData { Exception = ex, PluginName = shortName });
}
}

29
ILSpy/MainWindow.xaml.cs

@ -31,6 +31,7 @@ using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ICSharpCode.Decompiler;
using ICSharpCode.ILSpy.Debugger;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.TreeNodes;
@ -331,6 +332,34 @@ namespace ICSharpCode.ILSpy
}
NavigationCommands.Search.InputGestures.Add(new KeyGesture(Key.E, ModifierKeys.Control));
AvalonEditTextOutput output = new AvalonEditTextOutput();
if (FormatExceptions(App.StartupExceptions.ToArray(), output))
decompilerTextView.ShowText(output);
}
bool FormatExceptions(App.ExceptionData[] exceptions, ITextOutput output)
{
if (exceptions.Length == 0) return false;
bool first = true;
foreach (var item in exceptions) {
if (first)
first = false;
else
output.WriteLine("-------------------------------------------------");
output.WriteLine("Error(s) loading plugin: " + item.PluginName);
if (item.Exception is System.Reflection.ReflectionTypeLoadException) {
var e = (System.Reflection.ReflectionTypeLoadException)item.Exception;
foreach (var ex in e.LoaderExceptions) {
output.WriteLine(ex.ToString());
output.WriteLine();
}
} else
output.WriteLine(item.Exception.ToString());
}
return true;
}
#region Update Check

Loading…
Cancel
Save