我注册.NET程序集实现COM互操作性不公开我的方法 [英] Registering my .net assembly for COM interoperability doesn't expose my methods

查看:130
本文介绍了我注册.NET程序集实现COM互操作性不公开我的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,我要疯了。我一直试图做一个简单的.NET程序集可视作为COM对象使用,但它不工作。我一直在尝试不同的aproaches,但他们没有工作。迄今为止最接近我所得到的是一个用最少的属性,接口,手动注册等。

Ok, I'm going crazy. I've been trying to make a simple .net assembly visible to use as a COM object but it's not working. I've been trying a lot of different aproaches but none of them work. So far the closest i've got is the one with the least amount of attributes, interfaces, manually registering etc.

我有一个VBScript作为测试,看起来是这样的:

I have a vbscript as a test which looks like this:

Dim o
o = CreateObject("MyNamespace.MyClass")
msgbox o.Test()

我的C#code是这样的:

My c# code looks like this:

using System;
using System.Runtime.InteropServices;
namespace MyNamespace 
{
  [ProgId("MyNamespace.MyClass")]
  public class MyClass
  {
    public string Test()
    {
       return "teststring";
    }
  }
}

在我的项目(​​VS2008)我选择'使装配COM可见 - 里面加一个属性,我的AssemblyInfo.cs,我还检查了注册为COM互操作

On my project (VS2008) i've selected 'Make assembly COM visible' - which added an attribute to my AssemblyInfo.cs and i also checked 'Register for COM interop'.

我可以看到,真正的ProgId没有区别(在我的案件反正) - 只要我指定真正的命名空间+类名,我可以但覆盖它。我想这很好

I Can see that the ProgId really makes no difference (in my case anyways) - as long as i specify the real namespace+classname, i can however override it which i guess is nice.

现在的问题是 - 我的CreateObject顺利,但该方法测试()无法找到。事实上,如果我把DLL和提取TLB和期望,我看不出有什么方法都没有。

The problem is - my CreateObject goes well, but the method Test() can not be found. In fact if i take the dll and extract the tlb and expect that i see no methods at all.

我的错误是这样的:

C:\的Inetpub \ wwwroot的\ ASPTest \ testrun.vbs(3,   1)Microsoft VBScript运行时错误:   对象不支持此属性   或方法:测试

C:\inetpub\wwwroot\ASPTest\testrun.vbs(3, 1) Microsoft VBScript runtime error: Object doesn't support this property or method: 'Test'

我喜欢任何反馈,但只是为了让你知道我一直在努力。我的类插科打诨与GUID和AttributeGuid,明确定义标记有ComVisible特性的类以及我试着不让注册的COM互操作,而是做regasm / codeBase的/ REGFILE。

I'd love any feedback, but just to let you know what i've been trying. I've messing around with Guid and AttributeGuid on the class, defining the COMVisible explicitly on the class as well i tried NOT registering for COM interop and instead did regasm /codebase /regfile.

最后一个音符 - 我的大部分测试都围绕着一个非签名的程序集,但试图找出我试着用一个强名称/密钥和错误,但它没有做任何事情。

One last note - most my testing has revolved around a non-signed assembly, but trying to pinpoint the error i tried with a strongname/key as well but it didn't do anything.

谁能帮我看看这个问题,好吗?

Can anyone help me find the problem, please?

推荐答案

我开始从一开始就和我的项目COM互操作取出任何东西,然后我说

I started from the beginning and removed anything regarding COM interop on my project, i then added

[Guid(...some guid...)]
[ComVisible(true)]

在MyClass的,我增加了一个强名称(使用项目设置来设置它 - 而不是将其定义在AssemblyInfo.cs中的

on MyClass and i added a strongname (used the project setting to set it - instead of defining it in the AssemblyInfo.cs.

当我编译的程序集,我将文件复制到那里我做了其他位置

When i compiled the assembly, i copied the files to another location where i did a

regasm MyNamespace.MyClass.dll /codebase /regfile

然后我跑了,接受了注册表项。

Then i ran and accepted the registry entry.

这使得它的工作 - 每当我做出改变,我只是重新编译,并在旧(不注销)复制的文件,然后我只做:

This made it work - whenever i make changes i just recompile and copy the files over the old (no unregistering) and then i only do:

regasm MyNamespace.MyClass.dll /codebase

......,仅此而已 - 改变我对MyClass的取得是imediately可见我的VBScript和我的ASP页

... and that's it - changes i made to MyClass are imediately visible in my vbscript and in my asp page.

这篇关于我注册.NET程序集实现COM互操作性不公开我的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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