Regasm和COM互操作漏报 [英] Regasm and Com Interop false negatives

查看:352
本文介绍了Regasm和COM互操作漏报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图揭露通过COM我们的库,但似乎战斗工具多的实际问题。不管我怎么写我的COM类暴露我得到警告:XXX.dll不包含可以注册为COM互操作的类型(在项目属性标记项目作为注册COM互操作)。即使下面的简单类(如在装配体中唯一类是有符号和标记有ComVisible特性(假)标记)仍警告仍然存在:

I'm attempting to expose our library via COM but seem to be fighting the tools more than the actual problem. Regardless of how I write my COM exposed class I get the warning: "XXX.dll does not contain any types that can be registered for COM interop" (marked project as Register for COM interop in the project properties). Even the simple class below (as the only class in an assembly that is signed and marked with ComVisible(false)) still warning persists:

  [Guid("77699130-7D58-4d29-BE18-385871B000D1")]
  [ComVisible(true)]
  public interface IExample
  {
    string GetText();
    void SetText(string text);
  }

  [Guid("F91E5EE1-D220-43b5-90D1-A48E81C478B7")]
  [ComVisible(true)]
  public class Example : IExample
  {
    private string m_text = "default text";

    public string GetText()
    {
      return m_text;
    }

    public void SetText(string text)
    {
      m_text = text;
    }
  }



我试图在命令行中运行regasm上高兴地指出输出类型注册成功。然而,随着/详细开关没有额外的信息显示运行状态(我似乎记得它列出的名称或者只是注册类型的数量)。还试图运行与/ REGFILE开关regasm生成产生这样的REGFILE:

I've tried to run regasm from the command line on the output which gladly states "Types registered successfully". However, running with the /verbose switch no extra information is displayed (I seem to recall that it lists the name or perhaps just the number of registered types). Also tried running regasm with the /regfile switch to generate a regfile which generates this:

[HKEY_CLASSES_ROOT\ComExample.Example]
@="ComExample.Example"

[HKEY_CLASSES_ROOT\ComExample.Example\CLSID]
@="{F91E5EE1-D220-43B5-90D1-A48E81C478B7}"

[HKEY_CLASSES_ROOT\CLSID\{F91E5EE1-D220-43B5-90D1-A48E81C478B7}]
@="ComExample.Example"

[HKEY_CLASSES_ROOT\CLSID\{F91E5EE1-D220-43B5-90D1-A48E81C478B7}\InprocServer32]
@="mscoree.dll"
"ThreadingModel"="Both"
"Class"="ComExample.Example"
"Assembly"="COMInteropTesting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8568e57f6b170d6c"
"RuntimeVersion"="v2.0.50727"

[HKEY_CLASSES_ROOT\CLSID\{F91E5EE1-D220-43B5-90D1-A48E81C478B7}\InprocServer32\1.0.0.0]
"Class"="ComExample.Example"
"Assembly"="COMInteropTesting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8568e57f6b170d6c"
"RuntimeVersion"="v2.0.50727"

[HKEY_CLASSES_ROOT\CLSID\{F91E5EE1-D220-43B5-90D1-A48E81C478B7}\ProgId]
@="ComExample.Example"

[HKEY_CLASSES_ROOT\CLSID\{F91E5EE1-D220-43B5-90D1-A48E81C478B7}\Implemented Categories\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}]

我的任何措施没有COM向导,但在注册看起来有效的给我。然而,似乎没有任何其上运行的组件regasm时出现在注册表中。

I'm no COM wizard of any measure but the registration looks valid to me. However, nothing seems to appear in the registry when running regasm on the assembly.

所以我的问题是我是否缺少在我简单的例子,一些有报名工作,为什么我会看到错误指示,并登记实际上是正确的,我怎么能更好地确定COM注册的实际工作

So my question is whether I'm missing something in my simple example to have the registration work, am I seeing false indications and is the registration actually correct and how can I better determine if the COM registration actually works

编辑:
使用所建议的改变千电子伏我不能避免VS2008的警告,但在使用直接登记regasm(在注册表中没有正好从VS2008集成),我可以真正得到的东西登记。

Using the alterations suggested by Kev I could not avoid the warnings from VS2008 but I could actually get something registered in the registry using regasm directly (nothing in the registry from just the VS2008 integration).

我又试图让我有一个空的组装去除简单的类。在这个运行regasm没有报告任何形式的警告,只有成功注册类型。我看到这样的警告RegAsm:警告RA0000:无类型登记关于我的一些其他组件可能会错误地暴露在COM运行RegAsm时。这是怎么回事就在这里,可我相信,除了注册表中任何东西,怎么样从regasm开/关警告?

I then tried to remove the simple class so I had an empty assembly. Running regasm on this did not report any sort of warnings, only "Types registered successfully". I see warnings like "RegAsm : warning RA0000 : No types were registered" when running RegAsm on some of my other assemblies which may be incorrectly exposed to COM. What is going on here, can I trust anything except the registry and what about the on/off warnings from regasm?

推荐答案

我创建基于代码中的类库项目如下:

I created a class library project based on your code as follows:

在项目属性页中,选择签名选项卡。选中注册程序集复选框,并选择<新建...> 从选择强名称密钥文件:'下拉框

In the project properties page, select the Signing tab. Check the 'Sign the assembly' checkbox and select <New...> from the 'Choose a strong name key file:' drop down box.

然后我添加了下面的类(Example.cs)

I then added the following class (Example.cs):

[Guid("77699130-7D58-4d29-BE18-385871B000D1")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[ComVisible(true)]
public interface IExample
{
    [DispId(1)]
    string GetText();

    [DispId(2)]
    void SetText(string text);
}

[Guid("F91E5EE1-D220-43b5-90D1-A48E81C478B7")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class Example : IExample
{
    private string m_text = "default text";

    [ComVisible(true)]
    public string GetText()
    {
      return m_text;
    }

    [ComVisible(true)]
    public void SetText(string text)
    {
      m_text = text;
    }
}



然后我建这个项目后来降到了一个命令行。其中,DLL是从构建输出

I then built the project then dropped to a command line where the DLL was output from the build.

要进行注册:

regasm.exe COMInteropTesting.dll /注册/代码库/ TLB

如果您的组件需要将多个应用程序访问:

If your component needs to be accessible to multiple applications:

的Gacutil.exe -i COMInteropTesting.dll

这所有的Windows运行良好2003 32位,Windows 2008中的32位和Windows 7 64位。

This all worked fine on Windows 2003 32bit, Windows 2008 32bit and Windows 7 64 bit.

有一个问题是,虽然如果你正在测试的组件说CScript将在64位系统上,你需要运行正确的CScript解释。如果你注册的组件中采用32位 RegAsm.exe (在 C:\Windows\Microsoft.NET\Framework\v2.0.50727 ),那么你需要运行在 c中的32位的CScript解释:\Windows\SysWOW64

One gotcha though is that if you're testing the component with say CScript on a 64 bit system, you need to run the correct CScript interpreter. If you registered the assembly using 32bit RegAsm.exe (at C:\Windows\Microsoft.NET\Framework\v2.0.50727) then you need to run the 32 bit CScript interpreter at c:\Windows\SysWOW64.

这篇关于Regasm和COM互操作漏报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆