I'll try to explain what's going on, as I understand it. It appears you have the following workflow of calls (or objects being passing over): .NET 4.x -> COM -> .NET 3.5. Your Icom
interface is marshaled to COM like this (OleView):
[
odl,
uuid(81C99F84-AA95-41A5-868E-62FAC8FAC263),
version(1.0),
dual,
oleautomation,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "InteropTest.Icom")
]
interface Icom : IDispatch {
[id(0x60020000), propget]
HRESULT ReturnType([out, retval] _Type** pRetVal);
};
Note the _Type
which is unmanaged proxy for managed Type
class, implemented in mscorlib.dll
(type library mscorlib.tlb
). Its implementation is specific to each .NET Runtime version. Apparently, it gets created by .NET Runtime v4.0.
At some point later, you're trying to un-marshal it back, this time on .NET 3.5 side. If it was v4.0, you'd get back the same managed Type
object. However, with v3.5 you are getting an unamaged System.__ComObject
, which cannot be converted to v3.5 managed Type
object.