两种不相等,应该是 [英] Two Types not equal that should be

查看:150
本文介绍了两种不相等,应该是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调试使用反射来加载插件一些code

I'm trying to debug some code that uses reflection to load plugins

下面是调试code:

Type a = methodInfo.GetParameters()[0]
    .ParameterType.BaseType;
Type b = typeof(MessageContext);
Debug.WriteLine(a.AssemblyQualifiedName);
Debug.WriteLine(b.AssemblyQualifiedName);
Debug.WriteLine(a.Equals(b));

这里是它的输出:

And here is its output:

OrtzIRC.Common.MessageContext,OrtzIRC.Common,版本= 1.0.0.0,文化=中性公钥=空
  OrtzIRC.Common.MessageContext,OrtzIRC.Common,版本= 1.0.0.0,文化=中性公钥=空
  假

OrtzIRC.Common.MessageContext, OrtzIRC.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
OrtzIRC.Common.MessageContext, OrtzIRC.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
False

我不明白什么使这两类不同?

I don't understand what would make these two types different?

推荐答案

由不同的应用程序域[.NET]或类加载器【JAVA]不会比较平等的,不分配给/相互加载的同一类/类型直接。

The same class / type loaded by different app domains [.NET] or class loaders [Java] will not compare equal and are not assignable to/from each other directly.

您可能必须包含该类型的DLL的两个副本 - 一个由主程序加载并一个接的一个被载入的Assembly.Load *(......)方法?

You likely have two copies of the DLL containing that type - one loaded by the main program and one loaded by one of the Assembly.Load*(...) methods?

尝试显示/比较特性:
a.Assembly.Equals(b.Assembly)

a.Assembly.Location.Equals(b.Assembly.Location)

Try displaying / comparing the properties:
a.Assembly.Equals(b.Assembly)
and
a.Assembly.Location.Equals(b.Assembly.Location)

在一般情况下,你只需要每个DLL的一个副本,并把它装成一个单一的应用程序域。

In general, you only want one copy of each DLL and have it loaded into a single app domain.

这篇关于两种不相等,应该是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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