简体   繁体   English

如何正确注册VB.NET COM +组件的类型库?

[英]How do I properly register the Type Library of A VB.NET COM+ Component?

I am looking to upgrade legacy VB6 COM+ components to VB.NET components. 我希望将旧版VB6 COM +组件升级到VB.NET组件。 I have seemingly upgraded one already, called EventPackage, which has one class, IEventListener. 我似乎已经升级了一个叫做EventPackage的类,它具有一个IEventListener类。 Another, TradeOrders, Implements EventPackage.IEventListener . 另一个TradeOrders Implements EventPackage.IEventListener When attempting to build TradeOrders, I get the following Errors/Warnings; 尝试建立TradeOrders时,出现以下错误/警告;

  1. Cannot load type library for reference "EventPackage". 无法加载引用“ EventPackage”的类型库。 Library not registered. 图书馆未注册。 (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)) (来自HRESULT的异常:0x8002801D(TYPE_E_LIBNOTapped))
  2. The referenced component 'EventPackage' could not be found. 找不到引用的组件'EventPackage'。
  3. Type 'EventPackage.IEventListener' is not defined. 未定义类型'EventPackage.IEventListener'。

In the .vbproj, I notice this reference 在.vbproj中,我注意到此参考

<COMReference Include="EventPackage">
  <Guid>{0D76C094-21A6-4E04-802B-6E539F7102D7}</Guid>
  <Lcid>0</Lcid>
  <VersionMajor>2</VersionMajor>
  <VersionMinor>0</VersionMinor>
  <WrapperTool>tlbimp</WrapperTool>
</COMReference>

When I search the registry for this Guid, I find nothing. 当我在注册表中搜索此Guid时,什么也没找到。 When using GUIDs for similar COM+ objects, I find them in HKEY_CLASSES_ROOT\\CLSID\\{...}\\TypeLib ("..." being the GUID of the other component). 当对相似的COM +对象使用GUID时,我在HKEY_CLASSES_ROOT\\CLSID\\{...}\\TypeLib找到它们(“ ...”是另一个组件的GUID)。 When I go to the registry key name corresponding to EventPackage.IEventListener, I find that there is no \\TypeLib subkey. 当我转到与EventPackage.IEventListener对应的注册表项名称时,我发现没有\\TypeLib子项。 As you might suspect, searching the reg for "0D76C094-21A6-4E04-802B-6E539F7102D7" yields no results. 您可能会怀疑,在reg中搜索“ 0D76C094-21A6-4E04-802B-6E539F7102D7”不会产生任何结果。

So I know this must be a registry problem, But I have tried seemingly every google result I have found. 所以我知道这一定是注册表问题,但是似乎我已经尝试过发现的每个Google结果。 I have tried Regasm and regsvcs .exe's to no avail. 我尝试过Regasm和regsvcs .exe都无济于事。 Many pages just tell me that dragging the dll to the COM+ manager should automatically register the component. 许多页面只是告诉我,将dll拖到COM +管理器应该会自动注册该组件。

So how do I register the Type library? 那么如何注册类型库呢?

Details on how I made EventPackage COM+ component 有关如何制作EventPackage COM +组件的详细信息

  1. Ran the VB6->VB.NET wizard 跑VB6-> VB.NET向导

Then I added some lines to the assemblyinfo.vb file 然后我在assemblyinfo.vb文件中添加了几行

  1. added Imports System.EnterpriseServices 添加了Imports System.EnterpriseServices
  2. added Imports System.EnterpriseServices 添加了Imports System.EnterpriseServices
  3. Imports System.Data.SqlClient
  4. <Assembly: CLSCompliant(True)>
  5. <Assembly: AssemblyKeyFileAttribute("...")> for a strong name <Assembly: AssemblyKeyFileAttribute("...")>为强名称
  6. <Assembly: Guid("...")> (Where "..." is the COM+ CLSID of the old component) <Assembly: Guid("...")> (其中“ ...”是旧组件的COM + CLSID)

I added the following to the class file IEventListener.VB 我将以下内容添加到类文件IEventListener.VB中

  1. Imports System.EnterpriseServices
  2. <ComClass("...")> _ (Where ... is the proper COM+ CLSID, that is the only argument) <ComClass("...")> _ (哪里是正确的COM + CLSID,那是唯一的参数)
  3. Inherits ServicedComponent
  4. changed the ID made by the Conversion wizard to the proper value (from <System.Runtime.InteropServices.ProgId("IEventListener_NET.IEventListener)> to <System.Runtime.InteropServices.ProgId("EventPackage.IEventListener")> _ 将转换向导制作的ID更改为适当的值(从<System.Runtime.InteropServices.ProgId("IEventListener_NET.IEventListener)>更改为<System.Runtime.InteropServices.ProgId("EventPackage.IEventListener")> _

Then I dragged the DLL into the COM+ manager in the proper COM+ application (although, the "Path" is not specified and only says mscoree.dll ) 然后,我将DLL拖入正确的COM +应用程序中的COM +管理器中(尽管未指定“ Path”,而仅显示mscoree.dll

I had that dam error (0x8002801D (TYPE_E_LIBNOTREGISTERED)) yesterday, it drove me crazy: VSTO Add-ins, COMAddIns and RequestComAddInAutomationService 昨天我遇到了该大坝错误(0x8002801D(TYPE_E_LIBNOTrated)),这使我发疯: VSTO加载项,COMAddIns和RequestComAddInAutomationService

It might be a red-herring but my answer has similar details about reg keys not existing and etc: 这可能是一条红鲱鱼,但我的答案对不存在的注册表键等有类似的详细信息:

Right click on Visual Studio (2010) > Run As Administrator > Open Project > Compile! 右键单击Visual Studio(2010)>以管理员身份运行>打开项目>编译!

The console command "regsvr32 mydll.dll" will register your COM component. 控制台命令“ regsvr32 mydll.dll”将注册您的COM组件。 You should be able then to find the guid under HKEY_CLASSES_ROOT\\CLASSID then, under which the InprocServer32 folder will have the path to your dll. 然后,您应该能够在HKEY_CLASSES_ROOT \\ CLASSID下找到该GUID,在该GUID下,InprocServer32文件夹将具有您dll的路径。 This is how COM looks up the dll. 这就是COM查找dll的方式。

I think that the problem here is that you haven't generated a type library for your .NET component. 我认为这里的问题是您尚未为.NET组件生成类型库。 I know you said you used regasm - but did you use the right command line? 我知道您说过您使用了regasm,但是您使用了正确的命令行吗?

  • Start Menu => Programs => Microsoft .NET Framework SDK vX.Y => SDK Command Prompt . 开始菜单 => 程序 => Microsoft .NET Framework SDK vX.Y => SDK命令提示符
  • In this command line line, type: regasm /tlb:Mydll.dll 在此命令行中,键入: regasm /tlb:Mydll.dll

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM