@@ -42,7 +42,6 @@ public class _Extension : IDTExtensibility2
42
42
43
43
private IWindsorContainer _container ;
44
44
private App _app ;
45
- private IComSafe _comSafe ;
46
45
private readonly Logger _logger = LogManager . GetCurrentClassLogger ( ) ;
47
46
48
47
public void OnAddInsUpdate ( ref Array custom ) { }
@@ -52,9 +51,6 @@ public void OnConnection(object Application, ext_ConnectMode ConnectMode, object
52
51
{
53
52
try
54
53
{
55
- ComSafeManager . ResetComSafe ( ) ;
56
- _comSafe = ComSafeManager . GetCurrentComSafe ( ) ;
57
-
58
54
if ( Application is Microsoft . Vbe . Interop . VBE vbe1 )
59
55
{
60
56
_ide = new VBEditor . SafeComWrappers . VBA . VBE ( vbe1 ) ;
@@ -270,18 +266,6 @@ private void ShutdownAddIn()
270
266
_container . Dispose ( ) ;
271
267
_container = null ;
272
268
}
273
-
274
- if ( _comSafe != null )
275
- {
276
- _logger . Log ( LogLevel . Trace , "Disposing COM safe..." ) ;
277
- _comSafe . Dispose ( ) ;
278
- _comSafe = null ;
279
- _addin = null ;
280
- _ide = null ;
281
- }
282
-
283
- _isInitialized = false ;
284
- _logger . Log ( LogLevel . Info , "No exceptions were thrown." ) ;
285
269
}
286
270
catch ( Exception e )
287
271
{
@@ -291,11 +275,30 @@ private void ShutdownAddIn()
291
275
}
292
276
finally
293
277
{
294
- _logger . Log ( LogLevel . Trace , "Unregistering AppDomain handlers...." ) ;
295
- currentDomain . AssemblyResolve -= LoadFromSameFolder ;
296
- currentDomain . UnhandledException -= HandlAppDomainException ;
297
- _logger . Log ( LogLevel . Trace , "Done. Main Shutdown completed. Toolwindows follow. Quack!" ) ;
298
- _isInitialized = false ;
278
+ try
279
+ {
280
+ _logger . Log ( LogLevel . Trace , "Disposing COM safe..." ) ;
281
+ ComSafeManager . DisposeAndResetComSafe ( ) ;
282
+ _addin = null ;
283
+ _ide = null ;
284
+
285
+ _isInitialized = false ;
286
+ _logger . Log ( LogLevel . Info , "No exceptions were thrown." ) ;
287
+ }
288
+ catch ( Exception e )
289
+ {
290
+ _logger . Error ( e ) ;
291
+ _logger . Log ( LogLevel . Warn , "Exception disposing the ComSafe has been swallowed." ) ;
292
+ //throw; // <<~ uncomment to crash the process
293
+ }
294
+ finally
295
+ {
296
+ _logger . Log ( LogLevel . Trace , "Unregistering AppDomain handlers...." ) ;
297
+ currentDomain . AssemblyResolve -= LoadFromSameFolder ;
298
+ currentDomain . UnhandledException -= HandlAppDomainException ;
299
+ _logger . Log ( LogLevel . Trace , "Done. Main Shutdown completed. Toolwindows follow. Quack!" ) ;
300
+ _isInitialized = false ;
301
+ }
299
302
}
300
303
}
301
304
}
0 commit comments