Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have asp.net project (in .net 2.0) and I converted project to .net 4.0. After I built the project successfully, I launched the website on browser, it throws error as following:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

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

Source Error:

[No relevant source lines]

Source File: InternalXmlHelper.vb Line: 9

........

Please give me some idea to fix it.

like image 544
manh.phi Avatar asked Aug 24 '12 07:08

manh.phi


4 Answers

I had this problem, and listed below is what worked for me.

The clue was that the error message mentions InternalXmlHelper.vb. I am a C# programmer, so why the mention of a VB component?

This problem can arise if you have not been explicit about the compilation language for your ASPX page. If you have not been explicit, then IIS will compile in whatever is set as the default language for that site. If you are writing in C#, have not been explicit about the compilation language, and the default compilation language in IIS is C#, then happy days. But if the default compilation language in IIS is set to vb (which it seems it is by default), then your C# page is going to get compiled as if it were vb, and you get the BC30560 error.

The best fix is to be explicit as to the compilation language for your aspx pages, by putting a directive like this at the top of each of your aspx pages:

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

Alternatively, you can leave your pages ambiguous (no Page Language directive) and tell IIS what to use as the default compilation language, like this:

With IIS manager -> go look at the root of your websites (it will be your server name) then -> in the ASP.NET section -> double-click the .NET Compilation icon (blue down-arrow) -> in the list of settings, under the General heading, is a setting for Default Language -> set this to c#

You can also set the default language per website if you want. Same as above, but set it for a website below the root of the left-hand-side IIS tree view, instead of for the root of it. Note that if you set your default-language=c# for a website, that setting gets stored in the root web.config of your site - in the <system.web> section you'll have a value like this: <compilation debug="false" defaultLanguage="c#" />. If you delete or overwrite that setting in your web.config, it will revert to whatever is default for the IIS instance.

like image 192
Jinlye Avatar answered Oct 09 '22 15:10

Jinlye


A common trick to use extension methods (for LINQ etc) in .NET 2 with the C# 3 (or above) compiler 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 now-redundant extra attribute. Find where it is defined in your code and expunge it. Also check for external libraries like LINQBridge - you won't need this any more.

One way to find it would be to use the object browser and search for ExtensionAttribute.

like image 39
Marc Gravell Avatar answered Nov 20 '22 14:11

Marc Gravell


This was how I found the issue.

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 5
user1628777 Avatar answered Nov 20 '22 15:11

user1628777


I had this exact same error, and what solved it for me was to delete the Themes (under App_Themes). I haven't tried re-adding the themes to see if they'll work yet, but deleting that fixed the error, at least.

Note that I discovered it was the Themes causing this by looking at the compiler details in the error, and noting that the only .vb files it was compiling were related to themes (auto-generated). My project is all C#, so the error coming from VB made me look for the .vb files.

like image 2
yourzero Avatar answered Nov 20 '22 13:11

yourzero