tlbexp.exe changes method names' case

天大地大妈咪最大 提交于 2019-12-06 02:52:16

问题


I have a rather strange problem. I am exporting an interface from a C# library to COM. I have enabled the 'register with COM' project setting, so it calls tlbexp.exe to make the type libs.

We use camel case on our method names and I noticed that the exported type library changes these any method that happens to coincide with a class name to Pascal case...

e.g

interface IFoo
{
void randomClass()
}

class RandomClass
{
}

The exported IFoo in the type lib defines IFoo->RandomClass() instead of IFoo->randomClass()

Any ideas on what causes this and how to stop it?


回答1:


Since COM is case-insensitive, both "RandomClass" and "randomClass" are the same symbol in the output library's table. (This is part of the reason why the .NET guidelines recommend PascalCasing for class names and methods.)

The one that gets chosen will be the first one the compiler emits, and this is fairly non-deterministic from a programmer's point of view!

You can choose one or the other, using tlbexp's /names parameter, but both casings cannot co-exist in the library.

To use tlbexp's names file, you simply create a file with a list of identifiers, one per line:

RandomClass
SomeOtherIdentifier

Then you call it like so:

tlbexp MyAssembly.dll /names=MyNames.txt

tlbexp will then use the version of the symbol defined in the names file.



来源:https://stackoverflow.com/questions/3130280/tlbexp-exe-changes-method-names-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!