C# – How to access IMetaDataEmit and other MetaData COM interfaces from C# or F#

%fccomcom-interop

I am writing a compiler in F# and I want to be able to access the unmanaged metadata COM interfaces in the .net runtime. Before anybody mentions it, Reflection.Emit is not suitable for my purposes, nor do I want to use any other method than the metadata COM interfaces.

I've imported mscoree.tlb but it doesn't seem to include the interfaces I need.

The interfaces I'm interested in include IMetaDataEmit. Any sample code relating to this would be very useful, though I've not been able to find any so far.

C# samples would be fine as I can easily convert them to F#.

Thanks in advance to anybody who can help me with this rather cryptic query!

Update: I have now got this sorted by writing explicit COM references using the interface GUIDs!

Best Answer

One option here would be to create your own project and compile these interfaces (using their definitions from cor.h) into a type library, which you could then tlbimp into a managed assembly. I realize it would be pretty tedious to convert the C header code into IDL, but that could possibly be automated (or partially automated) by some text-processing scripts.