ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

c# – .NET Interop:在当前目录中使用程序集

2019-06-22 05:06:00  阅读:219  来源: 互联网

标签:c net interop vb6 com-interop


我试图通过interop从VB6使用.NET程序集而不将其放在GAC中,而不使用regasm.exe的/ codebase参数.

根据我的理解,当我在.NET类库上运行regasm.exe时,它会为类库中的每个类创建一个注册表项,告诉COM客户端他们应该加载mscoree.dll作为包装.NET对象的代理. COM使用. Mscoree.dll在类的注册表中使用InprocServer32 / Assembly键来确定哪个类库包含该类的实现.

如果我使用/ codebase和regasm.exe或将我的类库放在GAC中,一切正常;但据我从散乱的文档中可以看出,mscoree.dll应该在当前目录和路径中寻找汇编,如果/ codebase没有被使用(因此注册表中没有CodeBase条目)它在GAC中找不到它.

C#代码尽可能简单:

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace myinterop
{
    [Guid("B1D6B9FE-A4C7-11DD-B06B-E93056D89593")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ComVisible(true)]
    public class MyServer
    {
        public int Add(int a, int b)
        {
            return a + b;
        }
    }
}

问题再现了一个VBScript一个衬垫,我把它放在与编译的DLL相同的目录中:

object = CreateObject("myinterop.MyServer")

我在这里错过了什么?有没有明确的描述mscoree.dll在某处查找程序集的方式?

顺便说一句,我使用的是.NET 2.0,是的,我知道我应该将我的程序集放在GAC中,我只是想知道为什么这不像宣传的那样有效.

解决方法:

MSDN开始:

/Codebase : Creates a Codebase entry in the
registry. The Codebase entry specifies
the file path for an assembly that is
not installed in the global assembly
cache. You should not specify this
option if you will subsequently
install the assembly that you are
registering into the global assembly
cache. The assemblyFile argument that
you specify with the /codebase option
must be a strong-named assembly.

它似乎确实像宣传的那样工作.如果不将程序集放在GAC中,则需要使用/ codebase以便可以访问文件路径.

标签:c,net,interop,vb6,com-interop
来源: https://codeday.me/bug/20190622/1260936.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有