I have created an interface which I am inheriting from another (COM) interface:
public interface IDTSComponentMetaData : IDTSComponentMetaData90 { }
That's all it does.
The reason behind this is, depending on which version of SQL Server I am working with, the base may be IDTSComponentMetaData90 (2005) or IDTSComponentMetaData100 (2008). Rather than conditionally compile every reference to IDTSComponentMetaData90 / IDTSComponentMetaData100 in code, I'd like to use the version-neutral interface which will simply wrap the proper real interface.
The problem is that SSIS passes me an object to the native interface at one key point, and I need to cast it to my wrapper interface:
#if SQL2005
public void Initialize(IDTSComponentMetaData90 c,IServiceProvider s) {
#elif SQL2008
public void Initialize(IDTSComopnentMetaData100 c,IServiceProvider s) {
#endif
m_ComponentMetaData = (IDTSComponentMetaData) c;
m_ServiceProvider = s;
}
This compiles with no problem, but at run time, I get an 'Unable to cast COM object of type 'System.__ComObject' to interface type 'MyNameSpace.IDTSComponentMetaData'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{483E01E7-001C-35E4-Ac9f-4B0C1B81E409}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Is what I am doing totally wrong?