I have a base class that is written in C# that implements an interface defined in an IDL library. I have a C++ class that manages the single instance of this class. I also have a C# project that needs to make use of this class [instance (that is obtained through the C++ project)]. I want to cast the COM interface that my base class implements back into my C# base class.
However, when I cast the generic object that I acquired from the C++ proportion into my C# base class, I received an error. When I cast it to the derived interface, there is no problem.
Below is the similar example of my problem. The two if scopes are never evaluated in the NETBaseInstance function of CSDriver. The NETBase is the only class that implements COMInterface. So, I know for sure that the value is a NETBase since the if scope for COMInterface is evaluated.
public class NETBase : COMInterface{ ... }
public class CSDriver{
private NETBase m_NETBaseInstance;
...
public object NETBaseInstance{
set{
COMInterface test;
if( value is COMInterface ){
// This is evaluated.
test = value as COMInterface;
}
if( value is NETBase ){
// This is not evaluated.
m_NETBaseInstance = value as NETBase;
}
if( test is NETBase ){
// This is not evaluated.
m_NETBaseInstance = test as NETBase;
}
}
}
}
What is the process to cast this COM object to the C# object successfully? Am I doing something wrong?
Thank you in advance for any answers.