- Code: Select all
System.InvalidCastException: 'Unable to cast the provided managed object to a COM interface with ID '{c6fce4c9-c4e4-4047-82fb-5d238232a902}''
EDIT:
Ah, I made a mistake. When creating your own InputCallback class that implements the IDeckLinkInputCallback interface, it too has to be decorated with the [GeneratedComClass] attribute. Then it works.
Some pain points that you have to deal with manually as far as I know:
- COM interop methods that return an int (or an enum that's an int) have to be decorated with the [PreserveSig] attribute, or it will assume the return type is an HRESULT and mess everything up.
- COM interop methods that have the extern modifier will create a warning when compiling to Native AOT, saying it will always throw an exception because the IL is invalid.
I'm not sure what the proper solution is but I changed this:
public virtual extern void Next(out IDeckLink deckLinkInstance);
To this:
public virtual void Next(out IDeckLink deckLinkInstance)
{
// Won't be thrown - the source generator hides this implementation with the new modifier
throw new NotImplementedException();
}
Now I have everything I need for compiling C# .NET 8 to fast native binaries with no external dependency on .NET at all.