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

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.

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.

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.

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.

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.

This error is also because you don't have the page directive at the top of your aspx file. This is why VB compiler is used.
Write this to the top:
<%# Page Language="C#" %>

I had this error. Simply restarting Visual Studio made it go away.

This error also occurs in ASP.NET MVC Web Applications if you use an incorrect file extension for your views or partials.
I had inadvertently created a view using an incorrect extension (.ascx instead of .cshtml) and received this error message.
Changing the extension to .cshtml fixed the issue.

Related

Parser Error Message: Could not load type 'xxxx.Global'

Everything worked yesterday without any errors.
Today though, I created a new page and tried to load it, which returned an error. so I went and rebuilt the solution, and now I have this error on every page on my site.
error description:
Server Error in '/' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type 'xxxx.Global'.
Source Error:
Line 1: <%# Application Codebehind="Global.asax.cs" Inherits="xxxx.Global" Language="C#" %>
Source File: /global.asax Line: 1
I tried to look up the error, but the solutions I managed to find didn't solve the problem, I would love some help as I am truly lost about what had caused this.
EDIT: so I tried deleting the Global.asax file and running the site, which caused the first line in all my pages to return an error messege. still trying to find a solution.
Managed to solve it, Here's what finally worked for me -
first, in the first line of your aspx pages, Masterpage.Master and Global.asax you'll need to replace CodeBehind with CodeFile.
(in order to access your Global.asax code open it through the directory with a text editor).
after that, in your Global.asax.cs code, change public class Global : System.Web.HttpApplication to public partial class Global : System.Web.HttpApplication.
worth noting - this is a mishmash of a number of solutions that I found while googling, trying these separately first could also solve the bug.
You can try to set the CPU to x64 in visual studio to slove this issue:
On the menu bar, choose Build, Configuration Manager.
In the Active solution platform list, choose a 64-bit platform for the solution to target, and then choose the Close button.
If the platform that you want doesn’t appear in the Active solution platform list, choose New. The New Solution Platform dialog box appears.
In the Type or select the new platform list, choose x64.
If you want to copy the settings from a current platform configuration, choose it, and then choose the OK button.
If this does not solve your problem, you can also refer to the solution in this link:
Could not load type 'XXX.Global'.

code behind does not execute in dnn module

I have installed DNN server, and created new DNN module in Visual Studio, using Chris Hammond's project template. I have added module to DNN as extension, and its client-side works fine.
But I can not execute ASP.NET code behind part of project. I have tried to execute pre-generated Page_load() method, and also one button_click handler which I have constructed, but they just do not execute (I have tested with breakpoints, and also with code which should leave some trace in console, or in a file).
DNN documentation does not mention this issue.
What am I missing here ?
If you are using the WebForms pattern, on the .ascx file the top row will have AutoEventWireup="false" by default I believe. Change that to True. I've noticed a few people with this problem.
If this isn't the issue, make sure that you do not have a Cache time set in your .dnn manifest file.

asp.net cannot publish the asp namespace?

I use some statement with asp namespace, that likes ASP.controls1
when build, it is fine, and works well.
but when i publish, that is one error:
Error 120 c:\Projects\TideWeb\Controls\Common\ExceptionHelper\ExceptionHelper.ascx.cs(53): error CS0234: The type or namespace name 'controls_common_errorlist_errorlist_ascx' does not exist in the namespace 'ASP' (are you missing an assembly reference?)
Without example code, i try to help you by listing all error that i found in my way with the ASP namespace.
1) The UserControl 'ExceptionHelper.ascx.cs' is not used in current Page/UserControl.
You can try it: the ASP namespace appears in intellisense only if one or more UserControl are mentioned in the current page (or UserControl). If your code of mentioned UserControl contains compilation error, intellisense (and the compiler) ignore its name.
Fix the compilation error, and the name of your control get back.
2) The UserControl is registered into web.config file, and is used in a page (or UserControl) in the same directory. In this case you must re-register in the current page your UserControl by this tag:
<%# Register Src="~/MyControls/MyControl.ascx" TagPrefix="MyControls" TagName="MyControl" %>
Add this tag, and the error was fixed.
3) You mentioned:
"but when i publish, that is one error"
In some cases, my webApps won't compile correctly in the destination server, but in test all works well.
That compilation error can be a configuration error, permission of Temporary ASP.NET Directory, and the identity used by Application Pool.
If you can post some code, i could help you better.
what you said is ok but not enought. I had the same problem and solved but removing the ASP. part, so in example change this code
ASP.ascx_buscador buscador = new ASP.ascx_buscador();
for this one
ASCX_buscador = new ASCX_buscador();
and now everything's fine. Note that in the new code ASCX_ are now in capital (intellisense will help you)
found the solution on here:
Getting namespace name not found for ASP.net user control

Visual Studio 2008 losing intellisense for ASCX with CodeBehind (but works for CodeFile)?

I have the following definition at the top of my .ASCX file:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="ArticleView.aspx.cs" Inherits="MyNameSpace.ArticleView" %>
In that control I make use of <%= %> blocks to refer to members that I've declared in the code-behind file. If I compile and deploy the control, it works fine. But in Visual Studio I get a lot of design-time errors, "{some variable} does not exist in the current context." And Intellisense breaks too: it works for members of UserControl, but can't find my own declared members. There are other issues as well. In general, everything points to the fact that the ASP.articleview_ascx class getting generated is somehow not inheriting from the MyNameSpace.ArticleView class.
I've found that if I switch the CodeBehind attribute to "CodeFile":
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ArticleView.aspx.cs" Inherits="MyNameSpace.ArticleView" %>
suddenly Intellisense works and all the design-time errors disappear. But I don't want to do runtime compilation, or deploy my .ASCX.CS files - so I can't use CodeFile.
I've checked the simple stuff, like making sure that my CodeBehind filename is correct & the Inherits class has the proper namespace, etc. (And since it works properly after changing the attribute to CodeFile, those must be pointing at the right place....) But what am I missing? Why can't it handle the CodeBehind attribute?
Thanks,
Steve
Update: from a thread below - basic question was, why not just use CodeFile? Answer: when I try to deploy using CodeFile= in my files, after deploying I receive the following stack trace (presented in its entirety):
/_layouts/Pages/ViewPage.aspx.cs' does not exist. at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath) at System.Web.UI.TemplateParser.ProcessCodeFile(VirtualPath codeFileVirtualPath) at System.Web.UI.TemplateParser.ProcessMainDirectiveAttribute(String deviceName, String name, String value, IDictionary parseData)
(This is from a request to /_layouts/Pages/ViewPage.aspx. ViewPage is the page that has several other controls including the ArticleView mentioned in my original example. It just happens to be the first file that fails - if I go back to CodeBehind= in ViewPage, then included ASCX with CodeFile= will fail in the same way.) This seems to be the page compiler complaining because the inherited codebehind class can't be found in any loaded DLL, so it expects there must be a CS file to do on-demand compilation.
The issue here is that I don't want to deploy CS files, just ASPX/ASCX. Having read through many articles like this great one I'm aware of the various new models of deployment, although I've never used anything but a Web Application Project (converted forward from VS2003, we were late adopters of 2005 & the WAP model had already been added by the time we switched up from 2003.) Over many VS2005/8 projects, I've never had a problem with CodeBehind=, until this Intellisense issue showed up... though it doesn't help that in this case I'm deploying to SharePoint, which introduces a whole new level of complexity.
Since I've not deployed using CodeFile before, it's very likely that I'm missing some option I'm supposed to set in VS when building, in order to force a pre-compile. I just need to be able to deploy, as I do today, as a set of ASPX/ASCX with a single codebehind DLL. And that's working today with CodeBehind= ... it just has the originally mentioned Intellisense problem, which is really what I want to fix :)
Will post more as I identify what files might be relevant to the question...
Have you checked the Build Action on your project files? I have duplicated your issue by setting the Build Action on ArticleView.ascx.designer.cs to None. I can also compile when using CodeFile, etc..., I'm 99% sure that's your problem.
You are missing the [your-file].ascx.designer.cs file, which links your controls to your codebehind.
Just like CitizenBane suggestions, you need to right-click the file (or folders, or entire web project) and select "Convert to Application". Visual Studio will examine your ascx/aspx files for the server controls, and generate that designer file for you.
I actually ran into this myself, on a far larger scale... C#: How to convert a Website project to a Web Project
Check the answer.
This has happened to me before. Try right clicking the ascx/aspx and click on "Convert to Web Application". You may just be missing the generated controls. If you don't see it in the context menu, delete the designer generated file first.
CodeBehind is deprecated in .NET 2.0. I believe that only <= 1.1 uses "CodeBehind". Now it is "CodeFile" as you say.
Why do you not want to compile your code? If you compile you don't have to deploy your .cs files...
Why do you have the code behind for your ascx control as an aspx named page code behind?
A UserControl (ascx) usually has a codebehind of
CodeBehind="ArticleView.ascx.cs"
instead of what you have listed
CodeBehind="ArticleView.aspx.cs"
Notice the aspx instead of the ascx for a User Control.
That could be your problem... a simple typo or a copy and paste error. Couple possibilities come to mind:
Maybe you have the ascx control (User Control) specified above using a code behind file that is inheriting from System.Web.UI.Page instead of System.Web.UI.UserControl (that could be causing the Visual Studio errors).
You have the UserControl pointed at the code behind for a same name aspx page. Similar problem as #1 which would cause Visual Studio to get all confused.
Your files are name ArticleView.ascx and ArticleView.aspx.cs. This might confuse Visual Studio since I believe VS might expects a particular naming convention.
For a User Control (ascx) your files should be named:
ArticleView.ascx (CodeBehind="ArticleView.ascx.cs" Inherits="[NAMESPACE].ArticleView")
ArticleView.ascx.cs (inherits from System.Web.UI.UserControl)
ArticleView.ascx.designer.cs
For a Web From (aspx) your files should be named:
ArticlePage.aspx (CodeBehind="ArticlePage.aspx.cs" Inherits="[NAMESPACE].ArticlePage")
ArticlePage.aspx.cs (inherits from System.Web.UI.Page)
ArticlePage.aspx.designer.cs
This just happened to me in VS2010 after upgrading a web application project to .net 4.0.
The answer was to make sure you have targetFramework="4.0" set on the system.web/compilation section in web.config
i.e.
<system.web>
<compilation debug="true" targetFramework="4.0">
</system.web>

asp.net someusercontrol_ascx is defined in multiple places error

I've had this intermittent issue when using asp.net. My site is dynamically compiled. Sometimes when I modify a user control my web site complains that it is defined in multiple places. It almost seems like the old control did not get removed from the asp.net temporary files and the updated control is compiled to the same directory so it's defined in multiple places. That would make sense to me except for the fact that I have no control over what is in the Temporary ASP.net Files folder.
I've read that having circular references will cause this. I've made sure that I don't have circular references. Even with the simplest site I've seen this happen.
I've noticed that when using Master Pages this error seems to come up a lot more frequently.
I've read that a hotfix tries to fix this issue but I've gotten this error after applying the hotfix.
If I get the file causing the issue and make an edit to it then the error goes away. Even if I just put a space in the file it will resolve the error.
I can also get the error to resolve sometimes by visiting other pages of the site that might not use the user control and hitting refresh. This does not always work.
If I set the site to debug the error never happens. If I set it so that it comiles on a page by page basis then the error does not happen as much but still happens.
Below is what the error looks like.
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: CS1595: '_ASP.Header_ascx'
is defined in multiple places; using definition
from 'C:\WINNT\Microsoft.NET\Framework\v1.0.3705\Temporary
ASP.NET Files\root\afwew23d\asdfasd423\asdf23.dll'
Edit:
I'm using .net 2.0 (3.5) even though the error above says 1.0. I got that error from another source since I can't reproduce the issue every time. But the type of error is the same.
Edit 2:
Thanks gisresearch for your research. There was one statement in the link you provided:
One caution even if you have debug=false, is that if you go in and change something in one of your aspx pages, this page will have to be recompiled, but this doesn’t cause an appdomain reload so the whole application is not batch compiled again. This has the effect that the page will now get recompiled separately and get its own dll, so don’t change your aspx pages on a live server too often.
There is a setting in machine.config determining how many recompiles are allowed before the app domain restarts, by default it is set to 15, so after 15 recompilations the app domain will restart, just as it would if you touched the web.config or touched the bin directory.
This seems to say that when debug=false and the site has already been visited and compiled, if you change a page it will only compile that one page. That sounds like it could cause problems. I had thought changing a page or user control would cause the entire app to recompile.
Do you have two user controls with the same file name in diferent Folders of your Web App?
That sometimes will cause this issue.
If I set the site to debug the error
never happens.
when debug=true, the asp.net compiler don’t batch compile, when debug=false it does batch compile and may cause this issue.
The Read this post.
There is a conversation about the same issue.
re: ASP.NET Memory: If your application is in production… then why
is debug=true Monday, April 24, 2006
2:39 PM by Robbie Coleman We did get
an error for a UserControl that it
reported it could not load the
FileName_ascx class due to multiple
versions in the Temp ASP.NET folder.
We identified that we had two user
controls with the same file name in
diferent Folders of the same Web App.
The also had diferent namespaces and
never through this exception until we
set debug="false". We even wiped the
Temp ASP.NET directory clean on an
IISreset.
The only way we could fix the error,
was by renaming the ascx file of one
of the two.
Is this correct...? Was there a better
way to fix this?
BTW... [KissUpText] Tess, your posts
have been very helpfull to our
development team, and we really
appreciate all the information you
have given away. [/KissUpText]
re: ASP.NET Memory: If your application is in production… then why
is debug=true Tuesday, April 25, 2006
1:56 AM by Tess Hi Robbie,
Thanks for the nice comment:)
I am assuming that you are getting
"CS1595:
'UserControls.WebUserControl2' is
defined in multiple places; using
definition from
'c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary
ASP.NET
Files\usercontrols\293a1a4b\dbb2d387\cisxatg3.dll'
" or similar.
The problem basically occurrs if you
are using src rather than CodeBehind
and your cs or vb files contain a
definition for exactly the same class
in exactly the same namespace. The
error is really the same as what you
would get if you tried to compile a
dll with another class defined twice
in the same namespace.
The reason i am saying it happens when
you use src is because if you would
use CodeBehind you would have gotten
an error at compile time.
If the usercontrols are really the
same I would avoid creating a copy,
and instead using the one from the
other folder. If they are different I
would either give the different names
if possible, and if not, make sure
that the source classes are in
different namespaces, such as
ProjectName.FolderName.MyUserControl
The reason you are seeing it now and
not before is because you are now
batch-compiling everything into one
dll.
Hope this helps.

Resources