Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Compiler Warning 1685

So, (seemingly) out of the blue, my project starts getting compiler warning 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'

Perplexed, I researched the MSDN article to figure out its cause. Here's the information I found:

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.

Now I'm really scratching my head.

  1. I'm not running two different versions of the .NET Framework (unless you count 2.0 and 3.5).

  2. I'm not referencing any bizarre assemblies that might make me suspicious.

  3. I don't recall making any changes to my application that would spur this change.

  4. I've verified that all components target .NET Framework version v2.0.50727.

I'm open to suggestions, or ideas on how to correct this. I treat warnings as errors, and it's driving me crazy.

What really bugs me about it is that I don't know why it's occurring. Things that happen should have a discernable cause, and I should know why they happened. If I can't explain it, I can't accurately remedy it. Guesswork is never satisfactory.

The application is straightforward, consisting of a class library, and a windows forms application.

  • A C# class library DLL providing basic functionality encapsulating database access. This DLL references the following components:

    • System
    • System.Core
    • System.Core.Data
    • System.Data
    • System.Data.DataSetExtensions
    • System.Data.OracleClient
    • System.Drawing
    • System.Windows.Forms
    • System.Xml
    • System.Xml.Linq
  • A C# Windows Forms application providing the UI. This application references the following components:

    • CleanCode
    • CleanCodeControls (both of these provide syntax editor support, and are locally built against .NET 3.5).
    • LinqBridge
    • Roswell.Framework (the class library above)
    • System
    • System.Core
    • System.Data
    • System.Data.DataSetExtensions
    • System.Data.OracleClient
    • System.Deployment
    • System.Design
    • System.Drawing
    • System.Windows.Forms
    • System.Xml
    • System.Xml.Linq

Let me know if you need further information and I'll gladly provide it.

like image 339
Mike Hofer Avatar asked Mar 02 '09 16:03

Mike Hofer


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

Is C programming hard?

C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.


2 Answers

Another easy way to verify: In your code, temporarily use the class somewhere. Example:

System.Runtime.CompilerServices.ExtensionAttribute x = null; 

When building, this will generate error:

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

And show you immediately the 2 sources causing the conflict.

like image 61
Remco te Wierik Avatar answered Sep 22 '22 06:09

Remco te Wierik


LINQBridge makes me immediately suspicious. The entire intent of this is to provide extension attribute/methods etc for 2.0 users. If you have 3.5 (System.Core.dll), don't use LINQBridge. If you do need LINQBridge in 3.5 for some obscure reason (and I can't think of one), then you might have to use an extern alias. But I really doubt you need it!

like image 20
Marc Gravell Avatar answered Sep 20 '22 06:09

Marc Gravell