2009-03-02 181 views
43

所以,(貌似)出蓝色的,我的项目开始获得编译器警告1685:C#编译器警告1685

The predefined type 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias; using definition from 'c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll'

困惑,我研究的MSDN文章,找出其原因。这里是我发现的信息:

Visual C# Reference: Errors and Warnings Compiler Warning (level 1) CS1685

Error Message The predefined type 'System.type name' is defined in multiple assemblies in the global alias; using definition from 'File Name'

This error occurs when a predefined system type such as System.int32 is found in two assemblies. One way this can happen is if you are referencing mscorlib from two different places, such as trying to run the.Net Framework versions 1.0 and 1.1 side-by-side.

The compiler will use the definition from only one of the assemblies. The compiler searches only global aliases, does not search libraries defined /reference. If you have specified /nostdlib, the compiler will search for Object, and in the future start all searches for predefined types in the file where it found Object.

现在我真的很挠我的脑袋。

  1. 我不是运行两个不同的版本 .NET框架 的(除非你把2.0和3.5)。

  2. 我没有参考任何奇怪的 程序集,可能会使我 可疑。

  3. 我不记得对我的应用程序进行任何可能会引发此更改的更改。

  4. 我已验证所有组件的目标是.NET Framework版本v2.0.50727。

我很乐意接受有关如何解决此问题的建议或想法。我把警告视为错误,这让我发疯。

真的让我感到困扰的是,我不知道为什么它的发生。发生的事情应该有一个可辨别的原因,我应该知道他们为什么发生。如果我无法解释它,我无法准确补救它。猜测永远不会令人满意。

该应用程序很简单,由一个类库和一个Windows窗体应用程序组成。

  • C#类库DLL提供封装数据库访问的基本功能。该DLL引用以下组件:

    • 系统
    • System.Core程序
    • System.Core.Data
    • System.Data
    • System.Data.DataSetExtensions
    • System.Data.OracleClient的
    • System.Drawing
    • System.Windows.Forms
    • 的System.Xml
    • System.Xml.Linq的
  • 一个C#Windows窗体应用程序提供UI。此应用程序引用以下组件:

    • CleanCode
    • CleanCodeControls(这些提供语法编辑器支持,并建立本地对.NET 3.5)。
    • LinqBridge
    • Roswell.Framework(上面的类库)
    • 系统
    • System.Core程序
    • System.Data
    • System.Data.DataSetExtensions
    • System.Data.OracleClient的
    • System.Deployment
    • System.Design
    • System.Drawing中
    • System.Windows.Forms的
    • 的System.Xml
    • System.Xml.Linq的

让我知道如果你需要更多信息,我会很乐意提供它。

+0

看到以下内容:http://stackoverflow.com/questions/546819/strange-警告关于扩展属性 建议你关闭这个问题它是一个确切的重复 – ShuggyCoUk 2009-03-02 16:22:46

+0

顺便说一句,这确实是LinqBridge这是造成这种情况,你不再需要它 – ShuggyCoUk 2009-03-02 16:23:26

+0

我做了一个警告号码搜索,找不到任何问题包含它;我为重复道歉。顺便说一句,LinqBridge事实上是这个问题。谢谢! – 2009-03-02 16:29:22

回答

22

LINQBridge让我立即怀疑。这整个意图是为2.0用户提供扩展属性/方法等。如果你有3.5(System.Core.dll),不要使用LINQBridge。如果你需要3.5中的LINQBridge出于一些晦涩的原因(我想不出一个),那么你可能不得不使用一个外部别名。但我真的怀疑你需要它!

+0

是的,那是原因,好吧!太感谢了! – 2009-03-02 16:29:56

22

马克几乎肯定是正确的。这里有一个方法来验证

  1. 打开Reflector.exe
  2. 将所有
  3. F3的非系统组件和搜索ExtensionAttribute

如果它的任何地方弹出除了System.Core程序,那么你知道它来自哪里。

9

对于此问题的另一个解决方案是使用一个全球性的别名整机组装:

参考 - >属性 - >别名 - >替换“全球”别的东西

90

另一种简单的方法来验证: 在你的代码中,临时使用某个地方的类。 例子:

System.Runtime.CompilerServices.ExtensionAttribute x = null; 

建设时,这会产生错误:

The type 'System.Runtime.CompilerServices.ExtensionAttribute' exists in both 'c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll' and .....

而你立即显示在2个源引起冲突。

5

仅供参考:我有同样的问题,并能够通过使用Resharper的“优化引用”命令,然后删除所有未使用的引用来解决它。不完全确定为什么有效,但它确实。

-3

针对此问题的另一个解决方案=>右键单击项目 - >属性 - >建设 - >警告视为错误 - >无