I am getting an error in a C# 2008 application since I am trying to add the NLog open source tool to 2 different solution files.
I am completing the following task:
1. I add a reference to this dll in the references section of each proejct file.
2. I then place a 'using NLog' statment in each solution file.
No matter what I do, I can not remove 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias;
Can you show me code and/or tell me how to fix this problem?I am getting the following warning and error message for a C# 2008 application I am working on:
Warning 17 The predefined type 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias;
using definition from 'c:\Program Files (x86)\NLog\.NET Framework 2.0\NLog.dll' sample
Error 21 The type or namespace name 'Nlog' could not be found (are you missing a using directive or an assembly reference?) C:\Sample.cs 15 7 sample
Loading
VulpesPosted Nov 14, 2012, 3:33 PM
If there's a version of NLog which targets .NET 3.5 (IIRC from you're other threads, that's what you're using), then I'd use that. The likelihood is that the 'ExtensionAttribute' duplication has been dealt with in that version.
dcPosted Nov 14, 2012, 3:13 PM
I do have the following additional question to ask you which are:
You mentioned the following: "The System.Runtime.CompilerServices.ExtensionAttribute class was first added to the .NET Framework in version 3.5 (VS 2008) and is never needed in C#, though it is needed in VB.NET projects which create extension methods. However, it is part of mscorlib.dll and so can't be removed.".
However this is an error and I assume I need to remove the error so the application can complile clean? Thus what can I do for the application to compile clean?
Can I tell the build to ignore this error message and build any ways? If so, how would I do that using the visual studio.net 2008?
I also want to mention that one time when I was trying to determine what was wrong with the build, I pointed a reference to nlog that was for version 2.0 of the .net framework. Would that be causing a problem?
VulpesPosted Nov 14, 2012, 2:23 PM
The warning is more difficult.
The System.Runtime.CompilerServices.ExtensionAttribute class was first added to the .NET Framework in version 3.5 (VS 2008) and is never needed in C#, though it is needed in VB.NET projects which create extension methods. However, it is part of mscorlib.dll and so can't be removed.
It looks like NLog were using a similarly named attribute in the version of their software targeting .NET 2.0 and presumably therefore it's an integral part of NLog.dll and so can't be removed either.
As the compiler is selecting the correct version of ExtensionAttibute, it should be safe to ignore this warning. However, if you find it irritating, you can suppress it by going into the project's properties and, under the Build tab, place 1685 in the Suppress warnings text box.
You can also do it in code by placing this directive before any executable code in the file:
#pragma warning (disable : 1685)