• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

为什么从C#程序集生成的TLB会某些属性名称的前导字符小写

用户头像
it1352
帮助1

问题说明

这很奇怪:

我在C#中有一个界面:

This is odd:
I have an interface in C#:

[ComVisible(true)]
[Guid("24BDD90E-373B-400F-B374-1350CDB9FE76")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IGURecord
{
  [DispId(1)]
  string Id { get; }
  [DispId(2)]
  double GUValue { get; }
  [DispId(3)]
  double RelativeMigrationTime { get; }
  [DispId(4)]
  string GlycanName { get; }
  [DispId(5)]
  double MonoisotopicMass { get; }
}



在生成的.TLB中,GUValue,RelativeMigrationTime和GlycanName属性使得主要字符小写:


In the generated .TLB the GUValue, RelativeMigrationTime and GlycanName properties are getting the leading characters lowercased:

interface IGURecord : IDispatch {
    [id(0x00000001), propget]
    HRESULT Id([out, retval] BSTR* pRetVal);
    [id(0x00000002), propget]
    HRESULT guValue([out, retval] double* pRetVal);
    [id(0x00000003), propget]
    HRESULT relativeMigrationTime([out, retval] double* pRetVal);
    [id(0x00000004), propget]
    HRESULT glycanName([out, retval] BSTR* pRetVal);
    [id(0x00000005), propget]
    HRESULT MonoisotopicMass([out, retval] double* pRetVal);
};



有没有人对为什么会这样做有任何想法?



我尝试了什么:



我在这个C#程序集中没有任何异常。

这是VS 2013.

我在项目构建设置中检查了注册COM互操作。

此程序集中还有其他接口定义类似于未查看这个问题。


Does anyone have any ideas on why this could be happening?

What I have tried:

There isn't anything unusual I'm doing in this C# assembly.
This is VS 2013.
I've checked the "Register for COM interop" in the project build settings.
There are other interfaces in this assembly defined similarly that aren't seeing this issue.

正确答案

#1
好的,我要声称这是一个错误,虽然我不知道不知道它是在Visual Studio中,还是在REGASM.exe中创建Type库时:



似乎沿着这个过程的某个地方基于套管,标识符不被认为是完全唯一的。我在其他ComVisible接口上有方法,这些接口使用的参数使用相同的标识符,除了使用前导小写字母外。

我还注意到其他的东西:我在某些方法上有参数,这些参数与不同的属性名称相同。



预感,我重命名了所有的方法属性名称,以便它们不匹配任何具有不同外壳的标识符。

这解决了问题。

全部类型库中的标识符现在具有与定义C#接口相同的外壳。
OK, I'm going to claim this is a bug, although I don't know if it's in Visual Studio, or in REGASM.exe when it creates the Type library:

It seems that somewhere along the process identifiers are not being considered totally unique based on casing. I had methods on the other ComVisible interfaces that had parameters that used the same identifiers that were the problems here, except with the leading lowercase.
I also noticed something else: I had parameters on some methods that were cased the same as different property names.

On a hunch, I renamed all of the method property names so that they didn't match any identifiers with different casing.
That solved the issue.
All of the identifiers in the Type Library now have the same casing as in the defining C# interfaces.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfhhif
系列文章
更多 icon
同类精品
更多 icon
继续加载