How Does a COM Program Locate a .NET DLL Registered for COM Interop?

我的未来我决定 提交于 2019-12-23 07:57:21

问题


One customer wants to consume our .NET DLLs from VB6. They are designed to support reverse interop and all works fine... except: There are two separate VB6 programs in two different directories. It seems it's necessary to do one of:

  1. Copy the .NET DLL into both directories, or
  2. Install the .NET DLL in the GAC

This is the customer's observation and also supported by the RegAsm documentation:

After registering an assembly using Regasm.exe, you can install it in the global assembly cache so that it can be activated from any COM client. If the assembly is only going to be activated by a single application, you can place it in that application's directory.

I'm confused on this point.

First point of confusion:

As far as I understand, the COM runtime locates the DLL using the Prog ID / Class ID. When I look in the registry at the Class ID entry, I see the full path to the .NET DLL in the CodeBase key. Why is it that a COM program using the Prog ID / Class ID doesn't locate the .NET DLL using the CodeBase?

Second point of confusion:

The GAC is specific to .NET. How is it involved in resolving COM references?


回答1:


You're correct COM uses the ProgId to get to the ClassId to get to the COM server to load. In the case of .NET COM dlls, the COM server is actually MSCOREE, not the .NET dll (the value of the default key under {CLSID}/localserver32). MSCOREE, not COM, then can use whatever rules it wants to find the .NET assembly.

At this point, I don't know what .NET really does - that would require testing. You could watch yourself using FUSLOGVW. I can however guess it loads the assembly like it loads any other .NET assembly.

Assuming it just calls Assembly.Load() with the ClassName value, it'll follow the .NET binding rules. First look in the GAC, if not found will probe - so if a codebase is defined, it'll only look there, otherwise it will probe based on the application base (by default the directory of the app [but not for ASP.NET]).

I think that fits with what your read in regasm.

Your question is so old I assume it's been OBE, but the rules you'd use for putting assemblies in the app directory, use a codebase, or in the GAC are the same with and w/o com interop. Every situation is different and I haven't done enough .NET to give up any deep insights. I favor xcopy installs so I'd go with in the app directory (and use registration free COM) but there are other considerations like if the two vb apps must use the same version of the COM object.



来源:https://stackoverflow.com/questions/2867999/how-does-a-com-program-locate-a-net-dll-registered-for-com-interop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!