I’m working on a Windows Runtime component, written in C#, to wrap some COM interfaces that don’t have Windows Runtime equivalents, following this MSDN example which uses the interop interfaces provided by mbnapi.tlb. When I try to instantiate my IMbnInterfaceManager member in the wrapper class’s constructor, like so:
m_InterfaceManager = (IMbnInterfaceManager)new MbnInterfaceManager();
it throws a System.InvalidCastException due to E_NOINTERFACE (No such interface supported).
However, if I build my wrapper as a Class Library instead of a WinMD component, it works fine, with no other changes.
I’d much rather build this as a Windows Runtime component, so as not to limit the usefulness of the library. (At least one of the projects this is intended for is being written in Javascript/HTML.) Am I doing something wrong, or is what I’m trying to do not possible?
EDIT: Turns out it’s a bug in the .NET 4.5 RC. Leaving this question here in case anybody else runs into this issue, and I’ll post a workaround if I find one. Supposedly it’ll be fixed by RTM.
This has been confirmed as a bug in the .NET 4.5 RC, and purportedly will be fixed by RTM. The current workaround is to edit the .csproj file and set EmbedInteropTypes to False for the reference to the tlb/dll. This can cause the App Store Certification Test to fail, so be sure to set it back to True once the .NET bug is fixed.