.NET解决了一个类错误的DLL [英] .NET resolves a class to the wrong DLL

查看:103
本文介绍了.NET解决了一个类错误的DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的C#项目有两个第三方的DLL引用。这一点很重要,因为这意味着我没有访问源代码,不能修改或重新编译这两个DLL。

My C# project has references to two third party DLLs. This is important because it means I don't have access to source code and can't modify or recompile these two DLLs.

让我们称他们为DLL中和dll B.下面是DLL中的样子:

Let's call them dll A and dll B. Here's what dll A looks like:

namespace ThirdParty.Foo
{
  public class Bar
  {
    ...snip...
  }

  public class Something
  {
    public Bar MyProperty { get; set; }
  }
}

和这里是DLL B相类似:

And here's what dll B looks like:

namespace ThirdParty.Foo
{
  public class Bar
  {
    ...snip...
  }

  public class SomethingElse
  {
    public Bar MyProperty { get; set; }
  }
}



正如你所看到的,它们具有相同的命名空间而且他们都定义具有相同名称的类。我的C#代码需要两个DLL文件的引用。我用的参考别名属性能够在两个引用,我也外部别名firstDll 外部别名secondDll 我的C#文件的顶部。到目前为止好。

As you can see, they have the same namespace and they both define a class with the same name. My C# code needs a reference to both DLLs. I use the alias property on the reference to be able to distinguish between the two references and I also extern alias firstDll and extern alias secondDll at the top of my C# file. So far so good.

它似乎很明显,我认为 Something.MyProperty 的类型是firstDll.ThirdParty。 Foo.Bar和类型 SomethingElse.MyProperty 是secondDll.ThirdParty.Foo.Bar但由于某些原因,Visual Studio中会产生混乱而解决这两个属性的类型相同在firstDll 酒吧类。

It seems obvious to me that the type of Something.MyProperty is firstDll.ThirdParty.Foo.Bar and the type of SomethingElse.MyProperty is secondDll.ThirdParty.Foo.Bar but for some reason, Visual Studio gets confused and resolves the type of both properties to the same Bar class in firstDll.

有没有我逼的VisualStudio解决的正确类型的方式。

Is there a way for me to "force" VisualStudio to resolve the correct type?

编辑:$? b $ b我肯定让Visual Studio中的错误是:无法隐式转换类型'ThirdParty.Foo.Bar [D:\MySolution\References\Second.dll]'到'ThirpParty.Foo.Bar [D: \MySolution\References\First.dll]

the error I'm getting in Visual Studio is: Cannot implicitly convert type 'ThirdParty.Foo.Bar [d:\MySolution\References\Second.dll]' to 'ThirpParty.Foo.Bar [d:\MySolution\References\First.dll]'

推荐答案

创建一个DLL,将作为DLL中的包装。让我们把新的DLLC。然后,您的项目将引用DLL B和C。

Create a DLL that will serve as a wrapper for DLL A. Let's call the new DLL "C". Your project will then reference DLL B and C.

这篇关于.NET解决了一个类错误的DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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