Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 31 additions & 43 deletions source/Common/Common.VBIDETools/Commandbar/VbeCommandBarAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,61 +113,49 @@ protected virtual void Dispose(bool disposing)

using (new BlockLogger())
{
if (disposing)
{
RemoveCommandBarButtonClickHandlers();
}
DisposeUnmanagedResources();
_disposed = true;
}
}

private void DisposeUnmanagedResources()
/// <summary>
/// Unadvises the COM event sinks of the command bar buttons.
/// </summary>
/// <remarks>
/// Must run while the VBE is still alive (never from a finalizer).
/// If the sinks stay advised, the CLR finalizer unadvises them during process shutdown,
/// which crashes the host (access violation in combase.dll/clr.dll) and lets Office restart Access.
/// The buttons are not deleted here (issue #77: http://accunit.access-codelib.net/bugs/view.php?id=77).
/// </remarks>
protected void RemoveCommandBarButtonClickHandlers()
{
using (new BlockLogger())
{
Marshal.ReleaseComObject(VBE);
VBE = null;

// issue #77: (http://accunit.access-codelib.net/bugs/view.php?id=77)
return;
/*
try
while (_commandBarButtons.Count > 0)
{
while (_commandBarButtons.Count > 0)
var button = _commandBarButtons.Pop();
try
{
var button = _commandBarButtons.Pop();
try
{
Logger.Log(string.Format("Button: {0}, -ClickEventHandler", button.Button.Caption));
button.Button.Click -= button.ClickEventHandler;
}
catch (Exception ex)
{
Logger.Log(ex);
}
try
{
Logger.Log(string.Format("Button: {0}, Delete", button.Button.Caption));
button.Button.Delete();
}
catch (Exception ex)
{
Logger.Log(ex);
}
try
{
button.Dispose();
}
catch (Exception ex)
{
Logger.Log(ex);
}
button.Button.Click -= button.ClickEventHandler;
}
catch (Exception ex)
{
Logger.Log(ex);
}
Logger.Log("_commandBarButtons.Clear");
_commandBarButtons.Clear();
}
catch (Exception ex)
{
Logger.Log(ex);
}
*/
}
}

private void DisposeUnmanagedResources()
{
using (new BlockLogger())
{
Marshal.ReleaseComObject(VBE);
VBE = null;
}
}

Expand Down
3 changes: 2 additions & 1 deletion vbe-add-In/AccUnit.VbeAddIn/AccUnitCommandBarAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ protected override void Dispose(bool disposing)
{
if (disposing)
{
// managed resources:
// unadvise COM event sinks before the command bars are deleted
RemoveCommandBarButtonClickHandlers();
}

// unmanaged resources:
Expand Down
14 changes: 13 additions & 1 deletion vbe-add-In/AccUnit.VbeAddIn/TestStarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,19 @@ protected virtual void Dispose(bool disposing)
_codeWindowRunCurrentTestButton = null;
_projectWindowRunCurrentTestButton = null;

_accUnitSubMenuEvents = null;
if (_accUnitSubMenuEvents != null)
{
try
{
// unadvise COM event sink while the VBE is still alive
_accUnitSubMenuEvents.Click -= OnAccUnitSubMenuEventsClick;
}
catch (Exception ex)
{
Logger.Log(ex);
}
_accUnitSubMenuEvents = null;
}

if (VbeIntegrationManager != null)
{
Expand Down