I am trying to access a COM object (CST Studio Suite) through C#. I have previously successfully accessed and controlled this object through the following MATLAB script:
CST = actxserver('CSTStudio.Application'); % Opens CST
CST.FileNew(); % Creates a new file
MWS = CST.Active3D; % Set focus to the new file
MWS.invoke("AddToHistory","Test",""); % Append to history list
This is the C# code I am trying to use to control the COM object
cst_design_environmentLib.IApplication CST = new cst_design_environmentLib.Application(); // Opens CST
CST.FileNew(); // Creates a new file
dynamic MWS = CST.Active3D(); // Set focus to the new file
MWS.AddToHistory("Test", ""); // Doesn't work, produces an error
It all works up until I try to run the method AddToHistory
, which fails and gives the following error:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.__ComObject' does not contain a definition for 'AddToHistory'
I know that the method AddToHistory
exists because 1) I have accessed it through MATLAB and 2) it is here in the documentation. So why won't it run through C#? Since the MWS
object is dynamically typed, I get that the method won't be found at compile time, but it should still be found at runtime right? I have debugged and inspected the types of the objects and both CST
and MWS
are System.__ComObject
. When I inspect the dynamic view of these objects, it says "No further information on this object could be discovered" so it doesn't seem to be finding any methods.
Also, the type of CST
is part of the type library cst_design_environmentLib
so the methods such as FileNew()
are predicted by intellisense, but I don't believe that the type of MWS
is part of the type library.
Any help with this would be greatly appreciated.