BC30560: "ExtensionAttribute" is ambiguous in the namespace "System.Runtime.CompilerServices"

I have an asp.net project (in .net 2.0) and I converted the project to .net 4.0. After successfully creating the project, I launched the website in a browser, it gives an error as follows:

Compilation error

Description: An error occurred while compiling the resource required to service this request. Review the following specific error details and modify the source code accordingly.

Compiler Error Message: BC30560: 'ExtensionAttribute' is ambiguous in the namespace "System.Runtime.CompilerServices".

Source Error:

[There are no corresponding lines of source code]

Source file: InternalXmlHelper.vb Line: 9

........

Please let me know how to fix this.

+7
source share
6 answers

A common trick for using extension methods (for LINQ, etc.) in .NET 2 with the C # 3 compiler (or higher) was to define your own ExtensionAttribute in the right namespace.

Now that you have upgraded to a later version of .NET, you need to remove this extra attribute. Find where it is defined in your code and cross it out. Also check for external libraries such as LINQBridge β€” you won’t need it anymore.

One way to find this is to use the object browser and look for ExtensionAttribute.

+6
source

This is how I found the problem.

Another easy way to check: temporarily use a class in your code. Example:

System.Runtime.CompilerServices.ExtensionAttribute x = null; 

When building, this will result in an error:

Type of

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

and.....

And immediately show you 2 sources of conflict.

+4
source

I had the same error, and for me it decided to remove Themes (under App_Themes). I have not tried re-adding themes to see if they will work, but deleting this at least correcting the error.

Please note that I found that it was these themes that caused this by looking at the compiler details in error and noting that only the .vb files that it compiled were related to themes (with auto-generation). My project is all C #, so the error coming from VB made me search for .vb files.

+2
source

This error is also due to the fact that you do not have a page directive at the top of your aspx file. This is why the VB compiler is used.

Write this down at the top:

 <%@ Page Language="C#" %> 
0
source

I had this error. Just restarting Visual Studio made him quit.

0
source

This error also occurs in ASP.NET MVC web applications if you use the wrong file extension for your views or partial data.

I inadvertently created a view using the wrong extension (.ascx instead of .cshtml) and received this error message.

Changing the extension to .cshtml fixed the problem.

0
source

All Articles