1. <legend id='Eqtxu'><style id='Eqtxu'><dir id='Eqtxu'><q id='Eqtxu'></q></dir></style></legend>

    2. <i id='Eqtxu'><tr id='Eqtxu'><dt id='Eqtxu'><q id='Eqtxu'><span id='Eqtxu'><b id='Eqtxu'><form id='Eqtxu'><ins id='Eqtxu'></ins><ul id='Eqtxu'></ul><sub id='Eqtxu'></sub></form><legend id='Eqtxu'></legend><bdo id='Eqtxu'><pre id='Eqtxu'><center id='Eqtxu'></center></pre></bdo></b><th id='Eqtxu'></th></span></q></dt></tr></i><div id='Eqtxu'><tfoot id='Eqtxu'></tfoot><dl id='Eqtxu'><fieldset id='Eqtxu'></fieldset></dl></div>

        <tfoot id='Eqtxu'></tfoot>
        • <bdo id='Eqtxu'></bdo><ul id='Eqtxu'></ul>
      1. <small id='Eqtxu'></small><noframes id='Eqtxu'>

      2. 为 COM 互操作性注册我的 .net 程序集不会公开我的方法

        时间:2023-07-24
        1. <i id='5TG65'><tr id='5TG65'><dt id='5TG65'><q id='5TG65'><span id='5TG65'><b id='5TG65'><form id='5TG65'><ins id='5TG65'></ins><ul id='5TG65'></ul><sub id='5TG65'></sub></form><legend id='5TG65'></legend><bdo id='5TG65'><pre id='5TG65'><center id='5TG65'></center></pre></bdo></b><th id='5TG65'></th></span></q></dt></tr></i><div id='5TG65'><tfoot id='5TG65'></tfoot><dl id='5TG65'><fieldset id='5TG65'></fieldset></dl></div>
          <legend id='5TG65'><style id='5TG65'><dir id='5TG65'><q id='5TG65'></q></dir></style></legend>

          • <tfoot id='5TG65'></tfoot>

              <tbody id='5TG65'></tbody>

            1. <small id='5TG65'></small><noframes id='5TG65'>

                • <bdo id='5TG65'></bdo><ul id='5TG65'></ul>
                • 本文介绍了为 COM 互操作性注册我的 .net 程序集不会公开我的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  好吧,我快疯了.我一直在尝试使一个简单的.net 程序集可见以用作 COM 对象,但它不起作用.我一直在尝试很多不同的方法,但都没有奏效.到目前为止,我得到的最接近的是属性、接口、手动注册等数量最少的那个.

                  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# 代码如下所示:

                  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 运行良好,但找不到方法 Test().事实上,如果我获取 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.

                  我得到的错误是这样的:

                  The error i get is this:

                  C:inetpubwwwrootASPTest estrun.vbs(3,1) Microsoft VBScript 运行时错误:对象不支持此属性或方法:'测试'

                  C:inetpubwwwrootASPTest estrun.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.

                  谁能帮我找出问题?

                  推荐答案

                  我从头开始,在我的项目中删除了有关 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 所做的更改在我的 vbscript 和我的 asp 页面中立即可见.

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

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

                  上一篇:如何在 UWP 中从 IBuffer 或字节数组创建 IDirect3DSurface 下一篇:COM 互操作对象在一个项目中引发 InvalidCastException,但在其他项目中不引发

                  相关文章

                  <tfoot id='CARpp'></tfoot>
                  <i id='CARpp'><tr id='CARpp'><dt id='CARpp'><q id='CARpp'><span id='CARpp'><b id='CARpp'><form id='CARpp'><ins id='CARpp'></ins><ul id='CARpp'></ul><sub id='CARpp'></sub></form><legend id='CARpp'></legend><bdo id='CARpp'><pre id='CARpp'><center id='CARpp'></center></pre></bdo></b><th id='CARpp'></th></span></q></dt></tr></i><div id='CARpp'><tfoot id='CARpp'></tfoot><dl id='CARpp'><fieldset id='CARpp'></fieldset></dl></div>
                  • <bdo id='CARpp'></bdo><ul id='CARpp'></ul>

                    <small id='CARpp'></small><noframes id='CARpp'>

                    <legend id='CARpp'><style id='CARpp'><dir id='CARpp'><q id='CARpp'></q></dir></style></legend>