Why can't a .NET COM library be used via COM in .NET?

后端 未结 2 1372
情话喂你
情话喂你 2020-12-09 10:31

Now, I\'m aware that if the library is in .NET, it\'s a little pointless to access it via COM, however, I am a bit perplexed because if I were to ask someone to write a libr

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 10:53

    Tlbimp can see from the type library that it was produced from a .NET assembly. It just balks at what you are trying to do. Which doesn't make sense, if you want to use a .NET assembly then just add a reference to it.

    You can fool the machine by using late-bound COM, most easily done with the dynamic keyword in C#. That still doesn't fool the CLR, it can see that it interops with a managed assembly and won't actually create the COM-callable wrapper. You most typically do this to write a test program to test your COM server. The implication is that your test doesn't actually test the way your COM server is going to be used in practice. Very basic things like converting variants to objects and back just won't be tested at all. And may well give you very unpleasant surprises when you use the assembly in production.

提交回复
热议问题