COM +组件调用其他COM +组件 - "无法加载类型" [英] COM+ component calling other COM+ components - "Cannot load type"

查看:242
本文介绍了COM +组件调用其他COM +组件 - "无法加载类型"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有被注册为COM +组件两个.NET程序集,我从一个普通的控制台应用程序的测试工具测试它们;

 昏暗objFirst作为新MyFirstComponent()'COM +初始化
昏暗RC由于布尔= objFirst.GetValue()
 

该方法调用成功执行。这是MyFirstComponent的定义;

 <的ProgId(MyFirstComponent)> _
<的Guid(...)> _
< ClassInterface(ClassInterfaceType.None)> _
<交易(TransactionOption.Supported)> _
公共类MyFirstComponent
    继承的ServicedComponent
    实现IMyFirstComponent

    公共功能的GetValue()作为布尔实现IMyFirstComponent.GetValue
        昏暗objSecond作为新MySecondComponent()'COM +初始化
        昏暗RC由于布尔= objSecond.GetValue()
        返回RC
    端功能

末级
 

在哪里MySecondComponent被初始化的时候,我出现以下消息RemotingException;

  

无法加载类型'MySecondComponent',...,版本= ......,文化=中性公钥= ...

所有程序集强命名了。我不明白为什么我可以成功触发一个方法调用的第一个组成部分,但是,当它试图随后加载第二个组件本身,它无法解析的类型。

一点题外话,如果我在我的测试工具运行code从的GetValue()的机构,它按预期执行。这个问题似乎只冒出来一次的东西都搬进了COM +组件的境界调用其他COM +组件。

更新

我想我的问题收窄了。看来,COM +是坚持的东西的过程中,我只好跑我的客户对之前手动关闭的组件服务窗口中的COM +应用程序。这个问题之前,是,我是测试每一次我改变了一些东西(比如增加装配到GAC),时间客户端,由于某种原因,COM +仍然相信,大会也不会被发现。关闭应用程序下来,加入所需的程序集到GAC和运行客户端再次发挥预期。

这是罚款,客户端的概念我小的证明。于是我又回到了我真正的code和尝试过了,但现在我得到另一个奇怪的问题。我的COM +应用似乎无法找到他们的正常项目引用了。我真的不想下去添加的一切,它们引用到GAC的道路,所以我现在试图找出为什么我的正常的,非COM +引用不会得到解决。

解决方案

我终于找到了解决上述问题。我回答这个问题我来拯救其他人,我通过努力得到这个工作又痛苦。

  • 转到组件服务> COM +应用程序> YourComApplication

  • 弹出属性窗口YourComApplication和去激活选项卡。

  • 在应用程序根目录,提供中,你的DLL文件所在的路径。

  • 创建 application.manifest 的文件为您的COM +应用程序,并把它放在同一目录上面。一个范例文件看起来像这样;

 < XML版本=1.0编码=UTF-8独立=是&GT?;
<装配的xmlns =瓮:架构 - 微软COM:asm.v1
manifestVersion =1.0>
< /装配>
 

  • 在这最后一步,就是我以前错过了这个解决方案的将无法正常工作离不开它了。

此外,还要确保你有一个单独的目录为每个COM +应用程序。这种方法可以让你有一个基于.NET程序集调用对方多张COM +应用程序没有任何不必在GAC中。

I have a two .NET assemblies which are registered as COM+ components and I'm testing them from a regular console application test harness;

Dim objFirst As New MyFirstComponent() 'COM+ initialisation
Dim RC As Boolean = objFirst.GetValue()

The method call is executed successfully. This is the definition of MyFirstComponent;

<ProgId("MyFirstComponent")> _
<Guid("...")> _
<ClassInterface(ClassInterfaceType.None)> _
<Transaction(TransactionOption.Supported)> _
Public Class MyFirstComponent
    Inherits ServicedComponent
    Implements IMyFirstComponent

    Public Function GetValue() As Boolean Implements IMyFirstComponent.GetValue
        Dim objSecond As New MySecondComponent() 'COM+ initialisation
        Dim RC As Boolean = objSecond.GetValue()
        Return RC
    End Function

End Class

At the point where MySecondComponent is initialised, I get a RemotingException with the following message;

Cannot load type 'MySecondComponent', ..., Version=..., Culture=neutral, PublicKeyToken=...'

All assemblies are strongly named too. I cannot work out why I can successfully fire a method call to the first component, but when it tries to subsequently load up the second component itself, it can't resolve the type.

As a sidenote, if I run the code from the body of "GetValue()" in my test harness, it executes as expected. The problem seems to only crop up once things have moved into the realm of COM+ components calling other COM+ components.

Update

I think I am narrowing in on the problem now. It appears that COM+ was persisting something in process, and I had to manually shut down the COM+ applications from the Component Services window before running my client against it. The problem before was that I was testing the client every time I changed something (like adding the assembly to the GAC), and for some reason COM+ still believed that the assembly could not be found. Shutting the app down, adding the required assemblies to the GAC and running the client again worked as expected.

This was fine for my small proof of concept client. So I went back to my real code and tried it out, but now I am getting another strange issue. My COM+ applications seem unable to locate their normal project references now. I don't really want to go down the road of adding EVERYTHING that they reference to the GAC, so I'm now trying to work out why my normal, non-COM+ references aren't being resolved.

解决方案

I have finally found a solution to the problem described above. I'm answering the question myself here to save anyone else the pain that I went through trying to get this to work.

  • Go to Component Services > COM+ Applications > YourComApplication

  • Bring up the properties window for YourComApplication and go to the Activation tab.

  • Under "Application Root Directory", supply the path in which your DLLs reside.

  • Create an "application.manifest" file for your COM+ application and put it in the same directory as above. A sample file looks like this;

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
</assembly>

  • This final step is what I had missed before and this solution will not work without it.

Also, make sure that you have a separate directory for each of your COM+ applications. This approach will allow you to have mulitple COM+ applications based on .NET assemblies calling each other without anything having to be in the GAC.

这篇关于COM +组件调用其他COM +组件 - &QUOT;无法加载类型&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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