We are developing an Autodesk Inventor AddIn program and we are using MsTest framework to do some integration tests. Here is a very simple function, which creates a button definition with icon.
public ButtonDefinition GetButtonDef(Inventor.Application app, string m_clientId)
{
stdole.IPictureDisp icon16 = PictureDispConverter.ToIPictureDisp(InvAddIn.Properties.Resources.cp_logo_16x16);
stdole.IPictureDisp icon32 = PictureDispConverter.ToIPictureDisp(InvAddIn.Properties.Resources.cp_logo_32x32);
m_buttonDefinition = app.CommandManager.ControlDefinitions.AddButtonDefinition(
"My Command2", "MyCommand.InternalName",
CommandTypesEnum.kShapeEditCmdType, m_clientId,
"My description text","My tooltip text", icon16, icon32,
ButtonDisplayEnum.kAlwaysDisplayText
);
return m_buttonDefinition;
}
The doc of the API is here. When I run our AddIn under Inventor, this function is called and it works normally as expected. However, when I write a unit test to call this very same function in my test codes (in the same project), it throws the following COM Exception at the line where AddButtonDefinition is called:
System.Runtime.InteropServices.COMException: Catastrophic error (Exception of HRESULT: 0x8000FFFF (E_UNEXPECTED))
After a long time of trying I just found, when the both icons (icon16, icon32 as parameters) are omitted ( i.e. replaced with null ), then the test code would not throw exception.
I know this question might be too specific, but could someone give me some general hints: how comes the API behaves differently under the test environment, what can be the possible cause? Your input would be very appreciated!
In my opinion this is limitation of COM (or something similar). You can't access/share object of type IPictureDisp
between processes. I try to read StandardIcon
of existing Controldefinition
in external app (MSTest too) and I get COMException
. But the same code works inside AddIn.
I'm using MSTest for unit testing of business logic, but not for GUI creation. For this integration tests you can start Inventor with your addin and then check if the user controls are defined and are present in appropriate ribbon tabs and panels.