Skip to content

Commit 6043896

Browse files
committed
Shutdown COM error handler
1 parent 796e2e3 commit 6043896

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

Source/ExcelDna.IntelliSense.Host/ExcelDna.IntelliSense.Host.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
</Content>
6161
</ItemGroup>
6262
<ItemGroup>
63+
<None Include="ExcelDna.IntelliSense.Host-AddIn.xll.config">
64+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
65+
</None>
6366
<None Include="packages.config" />
6467
</ItemGroup>
6568
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

Source/ExcelDna.IntelliSense/IntelliSenseProvider.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,20 @@ void OnInvalidate()
483483
public void Dispose()
484484
{
485485
Logger.Provider.Info("WorkbookIntelliSenseProvider.Dispose");
486-
var xlApp = (Application)ExcelDnaUtil.Application;
487-
xlApp.WorkbookOpen -= Excel_WorkbookOpen;
488-
xlApp.WorkbookBeforeClose -= Excel_WorkbookBeforeClose;
486+
try
487+
{
488+
var xlApp = (Application)ExcelDnaUtil.Application;
489+
// might fail, e.g. if the process is exiting
490+
if (xlApp != null)
491+
{
492+
xlApp.WorkbookOpen -= Excel_WorkbookOpen;
493+
xlApp.WorkbookBeforeClose -= Excel_WorkbookBeforeClose;
494+
}
495+
}
496+
catch (Exception ex)
497+
{
498+
Logger.Provider.Verbose($"WorkbookIntelliSenseProvider.Dispose Error {ex}");
499+
}
489500
}
490501
}
491502

Source/ExcelDna.IntelliSense/LoaderNotification.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ void Notification(Reason notificationReason, IntPtr pNotificationData, IntPtr co
101101
}
102102

103103
#region IDisposable Support
104+
// CONSIDER: We might not need the finalizer support ...
104105
private bool disposedValue = false; // To detect redundant calls
105106

106107
protected virtual void Dispose(bool disposing)

0 commit comments

Comments
 (0)