C# 类型 <type> 存在于两个 DLL 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1057853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 07:11:00  来源:igfitidea点击:

The type <type> exists in both DLLs

c#.net

提问by pedrofernandes

I have 1 DLL in the .Net 3.5 framework and another in 2.0. The ListBoxItemclass exists in 2.0 and I have linked the class in the 3.5 DLL in the same namespace.

我在 .Net 3.5 框架中有 1 个 DLL,在 2.0 中有另一个。本ListBoxItem类存在于2.0和我都在同一个命名空间的3.5 DLL链接的类。

When I try to compile I get an "exists in both" error. How can I compile this and maintain the same structure.

当我尝试编译时,出现“两者都存在”错误。我如何编译它并保持相同的结构。

I don't want reference the 2.0 DLL to 3.5 to eliminate this problem, I want keep these DLLs separate.

我不想将 2.0 DLL 引用到 3.5 来消除这个问题,我想将这些 DLL 分开。

采纳答案by Bryan Rowe

This doesn't seem like a good idea no matter what, but change the namespaces and fully qualify your usages.

无论如何,这似乎都不是一个好主意,但是更改命名空间并完全限定您的用法。

Otherwise, why don't you just reference one dll?

否则,你为什么不只引用一个 dll?

回答by Adrian Godong

Split them into two different solutions, one for .NET 2.0 and the other for .NET 3.5. Otherwise, how would .NET knows how to load which one?

将它们拆分为两种不同的解决方案,一种用于 .NET 2.0,另一种用于 .NET 3.5。否则,.NET 怎么知道如何加载哪一个?

回答by Doguhan Uluca

This is a relevant solution as well, where you can define which type to use in your usings:

这也是一个相关的解决方案,您可以在其中定义要在使用中使用的类型:

https://stackoverflow.com/a/9194582/178620

https://stackoverflow.com/a/9194582/178620

You can't use fully qualified names when dealing with Extension methods and etc.

在处理扩展方法等时,您不能使用完全限定名称。

回答by Dave

Old thread but wanted to add in another instance where this issue occurred. Was delaing with a project that was converted from website to web application in Visual Studio 2010. I started to get the type "class" exists in both .../temporary ASP.NET/...yada...yada...yada.

旧线程,但想在发生此问题的另一个实例中添加。正在处理一个在 Visual Studio 2010 中从网站转换为 Web 应用程序的项目。我开始发现类型“类”同时存在于 .../temporary ASP.NET/...yada...yada ...亚达。

In my case, the old page used a datagrid to display a list of dates but the dataset was a list of classes List<MyClass>and the code in the .aspx (not code behind) was using the methodology of casting the data item for display...

就我而言,旧页面使用数据网格来显示日期列表,但数据集是类列表,List<MyClass>.aspx 中的代码(不是代码隐藏)正在使用将数据项转换为显示的方法......

<%# ((MyClass)Container.DataItem).MyDate %>

For some reason, MyClass was triggering the type error. After doing the full search throughout the project for any possible double class references and the like, did not find anything so basically decided to see if I got rid of the cast and just go with standard method of getting the value from the DataItem as follows:

出于某种原因,MyClass 触发了类型错误。在整个项目中对任何可能的双类引用等进行全面搜索后,没有找到任何东西,所以基本上决定看看我是否摆脱了演员阵容,只是使用从 DataItem 获取值的标准方法,如下所示:

<%# DataBinder.Eval(Container.DataItem, "MyDate").ToString()%>

And voila...no more type exists error. Not too sure why this would cause the above error to manifest itself (and if anyone has any insight, it would be appreciated) but the problem is gone...

瞧……没有更多类型存在错误。不太确定为什么这会导致上述错误出现(如果有人有任何见解,将不胜感激)但问题已经消失了......

Hope this helps someone...

希望这可以帮助某人...

Dave

戴夫