Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b918b08

Browse files
committed
Show details of type loader exceptions
git-tfs-id: [https://tfs.codeplex.com:443/tfs/TFS36]$/ResXResourceManager/Main;C37755
1 parent 53cf5c4 commit b918b08

1 file changed

Lines changed: 34 additions & 22 deletions

File tree

ResXManager.VSIX/VSPackage.cs

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Globalization;
1212
using System.IO;
1313
using System.Linq;
14+
using System.Reflection;
1415
using System.Runtime.InteropServices;
1516
using System.Windows;
1617
using System.Windows.Threading;
@@ -94,27 +95,38 @@ protected override void Initialize()
9495
{
9596
base.Initialize();
9697

97-
var path = Path.GetDirectoryName(GetType().Assembly.Location);
98-
Contract.Assume(!string.IsNullOrEmpty(path));
99-
100-
CompositionHost.AddCatalog(new DirectoryCatalog(path, @"*.dll"));
101-
CompositionHost.Container.ComposeExportedValue(nameof(VSPackage), (IServiceProvider)this);
102-
103-
ConnectEvents();
104-
105-
// Add our command handlers for menu (commands must exist in the .vsct file)
106-
var mcs = GetService(typeof(IMenuCommandService)) as IMenuCommandService;
107-
if (null == mcs)
108-
return;
98+
try
99+
{
100+
var path = Path.GetDirectoryName(GetType().Assembly.Location);
101+
Contract.Assume(!string.IsNullOrEmpty(path));
102+
103+
CompositionHost.AddCatalog(new DirectoryCatalog(path, @"*.dll"));
104+
CompositionHost.Container.ComposeExportedValue(nameof(VSPackage), (IServiceProvider)this);
105+
106+
ConnectEvents();
107+
108+
// Add our command handlers for menu (commands must exist in the .vsct file)
109+
var mcs = GetService(typeof(IMenuCommandService)) as IMenuCommandService;
110+
if (null == mcs)
111+
return;
112+
113+
// Create the command for the menu item.
114+
CreateMenuCommand(mcs, PkgCmdIdList.cmdidMyCommand, ShowToolWindow);
115+
// Create the command for the tool window
116+
CreateMenuCommand(mcs, PkgCmdIdList.cmdidMyTool, ShowToolWindow);
117+
// Create the command for the solution explorer context menu
118+
CreateMenuCommand(mcs, PkgCmdIdList.cmdidMySolutionExplorerContextMenu, ShowSelectedResourceFiles).BeforeQueryStatus += SolutionExplorerContextMenuCommand_BeforeQueryStatus;
119+
// Create the command for the text editor context menu
120+
CreateMenuCommand(mcs, PkgCmdIdList.cmdidMyTextEditorContextMenu, MoveToResource).BeforeQueryStatus += TextEditorContextMenuCommand_BeforeQueryStatus;
121+
}
122+
catch (ReflectionTypeLoadException ex)
123+
{
124+
// ReSharper disable once AssignNullToNotNullAttribute
125+
// ReSharper disable once PossibleNullReferenceException
126+
var text = "Error loading assemblies:\n\n" + string.Join("\n", ex.LoaderExceptions.Select(l => l.Message + ": " + (l.InnerException?.Message ?? string.Empty)));
109127

110-
// Create the command for the menu item.
111-
CreateMenuCommand(mcs, PkgCmdIdList.cmdidMyCommand, ShowToolWindow);
112-
// Create the command for the tool window
113-
CreateMenuCommand(mcs, PkgCmdIdList.cmdidMyTool, ShowToolWindow);
114-
// Create the command for the solution explorer context menu
115-
CreateMenuCommand(mcs, PkgCmdIdList.cmdidMySolutionExplorerContextMenu, ShowSelectedResourceFiles).BeforeQueryStatus += SolutionExplorerContextMenuCommand_BeforeQueryStatus;
116-
// Create the command for the text editor context menu
117-
CreateMenuCommand(mcs, PkgCmdIdList.cmdidMyTextEditorContextMenu, MoveToResource).BeforeQueryStatus += TextEditorContextMenuCommand_BeforeQueryStatus;
128+
MessageBox.Show(text, "ResX Resource Manager", MessageBoxButton.OK, MessageBoxImage.Error);
129+
}
118130
}
119131

120132
protected override void Dispose(bool disposing)
@@ -137,7 +149,7 @@ private EnvDTE80.DTE2 Dte
137149
return dte;
138150
}
139151
}
140-
152+
141153
[ContractVerification(false)]
142154
[SuppressMessage("ReSharper", "PossibleNullReferenceException")]
143155
private void ConnectEvents()
@@ -356,7 +368,7 @@ private void DocumentEvents_DocumentSaved(EnvDTE.Document document)
356368
// e.g. if custom tool is a text template, we might want not only to generate the designer file but also
357369
// extract some localization information.
358370
// => find the resource entity that contains the document and run the custom tool on the neutral project file.
359-
371+
360372
// ReSharper disable once PossibleNullReferenceException
361373
Func<ResourceEntity, bool> predicate = e => e.Languages
362374
.Select(lang => lang.ProjectFile)

0 commit comments

Comments
 (0)