swAddin 2011 Template (RPC_E_WRONG_THREAD)

vb.net

This is the error I get in my Try Catch... when I close Solidworks.

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'SolidWorks.Interop.sldworks.ModelDoc2'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B90793FB-EF3D-4B80-A5C4-99959CDB6CEB}' failed due to the following error: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD)).

   at MyAddin.SwAddin.DetachEventHandlers()

Can someone help me ?

SolidworksApi macros
Answers 4
BS
BS 2012-02-22 Best Answer

I have upgraded to the latest swAddin 2012 template.

Along with the error above I am also getting the following:

System.NullReferenceException: Object reference not set to an instance of an object.

   at SolidWorksTools.File.BitmapHandler.CleanFiles()

   at SolidWorksTools.File.BitmapHandler.Dispose()

   at MyAddin.SwAddin.DisconnectFromSW()

If you add a Try Catch to "DisconnectFromSW" you will get the same issue.

BS
BS 2012-02-24

Can anyone help me with this ?

RJ
RJ 2012-02-24

Brian,

What I could understand from your first post is that you are trying to cast a COM Object to a ModelDoc2 object. The error means that the COM object (you are trying to cast) can not be converted to a ModelDoc2 object because it does not have that interface.

The error in your second post says that the object you are using is NULL and has no memory assigned to it.

If you can share your code then a better explanation (and a solution) can be probably given.

Hope it helps!!!

Rajat Jain

BS
BS 2012-02-24

Hello Rajat,

After further testing, It seems that my usercontrol I am adding to the taskpane is causing this issue. I will do further testing this weekend and post back if my issue still persists.

Thanks for our time.

Brian