Circuitworks addin, can some one please fix the DisconnectModelViews Code in swCADFunc.dll

its been like this since 2016.  you are declaring your Object[] array = new object[]{Count} wrong 

try
Object[Count-1] array

your basically never disconnecting events from your model view handlers

plus it throws tons of exceptions when I am trying to debug my own code. 

Your Code

    public bool DisconnectModelViews()
{
bool flag;
try
{
int count = this.openModelViews.Count;
object[] array = new object[] { count };
this.openModelViews.Keys.CopyTo(array, 0);
foreach (ModelView view in array)
{
((ModelViewEventHandler) this.openModelViews[view]).DetachEventHandlers();
this.openModelViews.Remove(view);
view = null;
}
}
catch (Exception exception1)
{
Exception ex = exception1;
ProjectData.SetProjectError(ex);
Exception exception = ex;
ProjectData.ClearProjectError();
}
return flag;
}

‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

correct code

    public bool DisconnectModelViews()
{
bool flag;
try
{
int count = this.openModelViews.Count;
object[Count-1] array;
this.openModelViews.Keys.CopyTo(array, 0);
foreach (ModelView view in array)
{
((ModelViewEventHandler) this.openModelViews[view]).DetachEventHandlers();
this.openModelViews.Remove(view);
view = null;
}
}
catch (Exception exception1)
{
Exception ex = exception1;
ProjectData.SetProjectError(ex);
Exception exception = ex;
ProjectData.ClearProjectError();
}
return flag;
}

SolidworksSolidworks 2020 Beta