suddenly, error appears: the name does not exist - c#

Like some other SO postings, I am bugged with the error:
The name 'xxx' does not exist in the current context
and I tried lots of things, such as reboot, and clean and rebuild the solution.
The problem started when I moved ("cut" and "paste") a control in the Designer, so that in between, the control did not exist while it still was referenced in the Code *.cs file. Possibly it was invisibly given a slightly different internal windows name.
*.aspx:
<span id="span_msg" runat="server">Msg</span>
*.aspx.cs:
span_msg.InnerText = "the error is...";
*.aspx.designer.cs: this file does not exist, because this is a web site project, not a web application project. Yes, I know, its outdated, but it is too big to change.
Note that this code worked before I moved the control in the Designer. All other controls still work. But also a new control gives the same error.
I tried to analyze this systematically.
First of all, the build gives NO errors. Strange fact is that when debugging with F5, it says: build failed, do you want to continue with the last successful build? (default No), and the output window shows: error CS0103: The name 'span_msg' does not exist in the current context.
In the *.cs file, there is no error indication on the name 'span_msg'. Intellisense recognizes this name.
When, in the *.cs file, I rename to 'span_msgXXX', error indications are shown. When I remove the XXX, the error indications dissappear.
From this I conclude that VisualStudio "knows" from the connection between 'span_msg' in the *.cs and in the Designer.
Although this control worked before moving it with the Cut and Paste action, I tried to remove the control entirely, in Designer and in Code, and add a "regular" ASP control from the Toolbox, with a new ID name. Same strange problem with build OK, and the same F5 debugging "build error".
From this I conclude that the problem is not in the control, but in the Page. Somehow, the entire ASP Page is in some erroneous state, where the last, moved, control, and any newly added control, has something wrong.
So what happens differently from the build with no errors to the debugging with F5 and the "build error"? And how to fix this?
I know that the ID that is in the Designer is not the actual ID, and that the system adds some asp postfix to the ID, which is visible with the F12 browser dev tools.
Could it be that my page has started with assigning a new, different, postfix to the control ID's, which confuses the build process?
Update:
I guess, like Greg commented, that VisualStudio just somehow screwed up. As I could dispose of this page, and got my work fixed using another checkout of this page, I will not work further in trying to fix the problem on this particular page.
I did notice that the same error often is shown in the Error List window, with dozens, when an unrelated error occurs due to e.g. a missing semicolon, in an unrelated page or project of the same solution. Very strange indeed.

Related

Invalid Intellisense error CS0103 ASP.NET Web Site “The name does not exist in the current context”

I have got a big ASP.NET Website (so no designer.cs files), which I lately have converted from VS2012 to VS2017. Now in VS2017 dozens of Intellisense errors like
CS0103 The name 'DDLxyz' does not exist in the current context
CS0103 The name 'CBxyz' does not exist in the current context
appear in the error list. These did not appear in VS2012.
These are no real errors, but invalid Intellisense errors, which I do know because of
a) The site works. All the "not existing" controls work flawlessly.
b) The errors disappear from the error list when I select the filter "Build only", they appear when I select the filter "Build + Intellisense".
c) Strange but true: when I double click such an error in the error list, the according aspx.cs file opens in VisualStudio and shortly thereafter, the errors concerning this file vanish from the list and also the red squiggly lines in the file vanish. So somehow VS must know that all these errors are invalid.
What I've got from other similar questions here on SO:
Closing and reopening VS, cleaning the solution, rebuilding does not help. In contrary: When I made the errors vanish by applying point (c) above and do a clean solution and rebuild, the errors show up again. Sometimes.
A workaround recommends 'Use the "Build only" filter' in the error list. This works, but i am not content with it. I'd like to have other Intellisense errors shown.
A workaround recommends disabling the error CS0103 via the filter options. I found no way to do this in my version of VS2017 v 15.9.14. I found no way to disable just CS0103 in a website project.
The filter options do only show "error, warning, message" but no single error numbers.
(If it was possible, I wouldn't like the solution too much, as there might be real errors of this kind be filtered away. But I'd nevertheless take this workaround.)
Some recommend to rebuild the designer.cs file. But this is a website project, there are no designer.cs files at all.
I don't want these invalid errors to show up in the error list.
If there is no other way, I would also use a possibility to switch off all CS0103 errors for this project.
Delete your .vs folder and then rebuild the solution. That should remove all those Intellisense errors.
Assuming your VS2012 and VS2017 are in the same machine.
You can try:
1.Navigate to the folder where WebsiteName.sln exists, since it was created in VS2012, it should have a xx.suo file in that directory. And after you open it in VS2017, it will also have a hidden .vs folder.
2.Close all VS instances and delete the .vs folder and xx.suo file
3.Clean the VS cache. C:\users[USER]\AppData\Local\Microsoft\VisualStudio\12.0 and C:\users[USER]\AppData\Roaming\Microsoft\VisualStudio\12.0. I also delete the 15.0 for VS2017, after that reopen vs to check if this issue go away.

Ambiguous reference intellisense error from Resource.Designer.cs

I am running into a peculiar bug when developing on Visual Studio 2017 that I have been able to ignore for a while, but is now beginning to really bug me.
I refer to this issue as a bug rather than an error because I am still able to build my projects in Visual Studio and deploy them to my development device without errors or warnings from the build output. This might seem alright to ignore for a bit, but over time it has become an issue because my intellisense is underlining it in red as an error
every time I reference attributes from the Resource class. As you might guess, I refer this class a lot and the Visual Studio editor eventually becomes cluttered with these "errors" which (a) hinders my ability to find actual errors in my code and (b) irritates me beyond all reason...
"Error" Investigation
As shown in the last image, intellisense is picking up an "Ambiguous Reference" to each attribute in the Resource class. When I check my Resource.Designer.cs file I only see one reference, but get a second error
.
It is now telling me that that a "Member with the same name is already declared". This lead me to believe that there is a second Resource.Designer.cs file, but my solution explorer and windows explorer both show only one.
Attempted solutions
Changed the namespace from InventoryApp (the default namespace of the file) to InventoryApp.Resources. This rid me of the ghastly errors but, upon building the project, it reverts the namespace in the file back to it's default, and the errors pop back up. I was also told by somebody who knows better that this is a big no-no.
Deleted the Resource.Designer.cs file, deleted the "obj" and "bin" folders from the project, cleaned and rebuilt the solution, then added the new Resource.Designer.cs file back to my solution. This did nothing to solve the problem.
Created an entirely new project from scratch. Even after creating a Blank Android App from the Visual Studio templates, the error persists. This begs the question: Is this a problem with my installation of Xamarin.Android?
Side-notes
The Resource.Designer.cs file's Build Action is set to "Compile"
The .csproj config file contains the tags:
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
6/6/2018 Update
If you have ReSharper, you most likely will be able to disregard my per-project solution described below and, instead, simply install the latest version (currently ReSharper 2018.1.2). Apparently, the underlying issue was caused by a bug in a previous version. Upgrading resolved the issue for me.
See youtrack.jetbrains.com/issue/RSRP-469636 for more information.
Thanks to #davidbauduin over at Xamarin Forums for this information.
I believe I have figured out the underlying issue and have a viable solution.
Solution
Add the following to the <PropertyGroup> section in your .csproj file:
<AndroidUseManagedDesignTimeResourceGenerator>False</AndroidUseManagedDesignTimeResourceGenerator>
Reason
While previous versions of Visual Studio had that feature turned off by default, the latest VS2017 update (15.7.3) has it turned on. That feature generates a second Resources.Designer.cs file that results in the ambiguous reference issue.
You can verify by hovering over the resource constant with the Intellisense error, right-clicking, selecting "Go To Definition", and selecting the 1st item, which takes you to a Resource.Designer.cs file. If you repeat, but select the 2nd one, you'll be taken to a different Resource.Designer.cs file. One of these points to the obj\Debug\designtime\Resource.Designer.cs file. By setting that feature to False as described above, that Resource.Designer.cs file in the obj\Debug\designtime path will not be generated.
Information Regarding the AndroidUseManagedDesignTimeResourceGenerator Feature:
https://developer.xamarin.com/releases/android/xamarin.android_8/xamarin.android_8.1/#design-time-builds-managed-resource-parser
https://github.com/dotnet/project-system/blob/master/docs/design-time-builds.md#design-time-builds
Hope this helps!

Visual studio - getting error "Metadata file 'XYZ' could not be found" after edit continue

I have stumbled into an issue that is really annoying.
When I debug my software, everything runs OK, but if I hit a breakpoint and edit the code, when I try to continue running I get an error:
Metadata file 'XYZ' could not be found
After looking around for a while, I found some a similar issues, but they were all regarding a build failure, which is not my case (this happens only after edit-continue).
What I have tried so far:
My code is compiling and running.
I cleaned the solution and restarted VS.
I made sure that the missing file's project is being build for the configuration I am running (in configuration manager).
I manually built the missing file's project.
Some extra info:
It does not matter what I change, still get the same error (the change is not related to the missing file).
This happens also when I pause and continue (not only breakpoints)
I am running the project using a custom configuration (configuration manager...). When I run it using the default Debug configuration the error does not occur.
Any ideas?
Eventually what solved the issue was:
Clean every project individually (Right click> Clean).
Rebuild every project individually (Right click> Rebuild).
Rebuild the startup project.
I guess for some reason, just cleaning the solution had a different effect than specifically cleaning every project individually.
Edit:
As per #maplemale comment, It seems that sometimes removing and re-adding each reference is also required.
Update 2019:
This question got a lot of traffic in the past, but it seems that since VS 2017 was released, it got much less attention.
So another suggestion would be - Update to a newer version of VS (>= 2017) and among other new features this issue will also be solved
As far as I can tell, this happens when the project dependencies gets messed up for whatever reason (whilst all the inter-project references are still intact). For many cases, it is NOT a code issue. And for those who have more than a few projects, going through them one at a time is NOT acceptable.
It's easy to reset project dependencies -
Select all projects and right click unload
Select all projects and right click reload
Rebuild solution
For those who have an issue in their code or some other issue that's causing this problem you'll obviously have to solve that issue first.
One possible reason could be you have upgraded the some of your projects (in the solution) to higher version e.g. from .NET 4.0 to 4.5 This happened in my case when I opened the solution in VS 2013 (originally created using VS 2010 and .NET 4.0). When I opened in VS 2013 my C++ project got updated to .NET 4.5 and I started to see the problem.
Generally this kind of error comes with human mistakes like if we change the namespace in some improper way, or changing folder names from explorer for current project etc, where compiler is unable to detect sometimes.
I came across the same error, to resolve which I tried few steps. Please follow all the steps :
Clean whole Solution
Right Click on every Project in your solution , Go to Properties and make your Default namespace as well as Default assembly name same as in your code (i.e namespace before class name)
Check Folder names for each project by going through the explorer(Where your project solution is). If not matching with your project names, make it similar (Like step 2) to them.
Remove all your references from each project relevant to another of same solution, and add it again.
In Your Project Solution folder, you will find Visual c# Project file. Right click and open with Notepad. In your initial lines you would find for lines for every project like below:
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "**Client**", "**Client** \ **Client**.csproj", "{4503E259-0E3B-414A-9074-F251684322A5}"
EndProject
Check again Foldernames (I have highlighted in BOLD) and make it similar to what you did in step 2.
Clean the whole solution again
Build The Solution (If doesn't work try building individual after cleaning again)
Make sure all your dependent projects are using the same .Net Framework version. I had the same issue caused by a dependent project using 4.5.1, while all others were using 4.5. Changing the project from 4.5.1 to 4.5 and rebuilding my solution fixed this issue for me.
XYZ couldn't be found because is not built yet....
Right click on the solution and check Project Dependencies, the Project Build Order should also change according to the dependencies that have been set.
The only thing that worked for me was to delete the Solution User Options (.suo) file. Note that, this is a hidden file.
To locate this file, close your Virsual studio and search for .suo from the file explorer within your project.
PS: a new .suo file will be created again when you rebuild your project and hopefully this newly created one wont give you issues.
I hope that helps someone get rid of this anoying error :).
I had this problem for days! I tried all the stuff above, but the problem kept coming back. When this message is shown it can have the meaning of "one or more projects in your solution did not compile cleanly" thus the metadata for the file was never written. But in my case, I didn't see any of the other compiler errors!!! I kept working at trying to compile each solution manually, and only after getting VS2012 to actually reveal some compiler errors I hadn't seen previously, this problem vanished.
I fooled around with build orders, no build orders, referencing debug dlls (which were manually compiled)... NOTHING seemed to work, until I found these errors which did not show up when compiling the entire solution!!!!
Sometimes, it seems, when compiling, that the compiler will exit on some errors... I've seen this in the past where after fixing issues, subsequent compiles show NEW errors. I don't know why it happens and it's somewhat rare for me to have these issues. However, when you do have them like this, it's a real pain in trying to find out what's going on. Good Luck!
Well, my answer is not just the summary of all the solutions, but it offers more than that.
Section (1):
In general solutions:
I had 4 errors of this kind (‘metadata file could not be found’) along with 1 error saying 'Source File Could Not Be Opened (‘Unspecified error ‘)'.
I tried to get rid of ‘metadata file could not be found’ error. For that, I read many posts, blogs etc and found these solutions may be effective (summarizing them over here):
Restart VS and try building again.
Go to 'Solution Explorer'. Right click on Solution. Go to Properties. Go to 'Configuration Manager'. Check if the checkboxes under 'Build' are checked or not. If any or all of them are unchecked, then check them and try building again.
If the above solution(s) do not work, then follow sequence mentioned in step 2 above, and even if all the checkboxes are checked, uncheck them, check again and try to build again.
Build Order and Project Dependencies:
Go to 'Solution Explorer'. Right click on Solution. Go to 'Project Dependencies...'. You will see 2 tabs: 'Dependencies' and 'Build Order'. This build order is the one in which solution builds. Check the project dependencies and the build order to verify if some project (say 'project1') which is dependent on other (say 'project2') is trying to build before that one (project2). This might be the cause for the error.
Check the path of the missing .dll:
Check the path of the missing .dll. If the path contains space or any other invalid path character, remove it and try building again.
If this is the cause, then adjust the build order.
Are you using a database code generation tool like SQLMETAL in your project?
If so, you may be facing a pluralized to unpluralized transition issue.
In my case, I have noted that some old pluralized (*) table names (upon which SQLMETAL adds, by default, an "s" letter at the end) table references to classes generated by SQLMETAL.
Since, I have recently disabled Pluralization of names, after regerating some database related classes, some of them lost their "s" prefix. Therefore, all references to affected table classes became invalid. For this reason, I have several compilation errors like the following:
'xxxx' does not contain a definition for 'TableNames' and no extension method 'TableNames' accepting a first argument of type 'yyyy' could be found (are you missing a using directive or an assembly reference?)
As you know, I takes only on error to prevent an assembly from compiling. And that is the missing assemply is linkable to dependent assemblies, causing the original "Metadata file 'XYZ' could not be found"
After fixing affected class tables references manually to their current names (unpluralized), I was finnaly able to get my project back to life!
(*) If option Visual Studio > Tools menu > Options > Database Tools > O/R Designer > Pluralization of names is enabled, some SQLMETALl code generator will add an "s" letter at the end of some generated table classes, although table has no "s" suffix on target database. For further information, please refer to http://msdn.microsoft.com/en-us/library/bb386987(v=vs.110).aspx
Hope it helps!
I had this error come up. I followed all of the solutions here but nothing worked. I was using Visual Studio 2013 Professional. I couldn't get the individual project rebuilds to work and I finally figured out there was a circular dependency in my references. Visual Studio does a pretty good job normally of warning you if you are adding a reference to something that references back, but for some reason it didn't in this instance. I added a reference to a project that referenced the project I was working on - and it accepted it. VS bug perhaps?
My 5 cents.
This problem started after a solution wide clean.
I managed to get the problem to go away by setting the Active Solution configuration in: Build -> Configuration manager to release. Then build and set it back to debug again. The build succeeded after that.
Close VS, locate and remove the 'packages' folder from outside of visual studio. Restart VS and build -> all dependencies are reinstalled
Visual Studio 2019 Community 16.3.10
I had similar issue with Release build. Debug build was compiling without any issues.
Turns out that the problem was caused by OneDrive. Most likely one could experience similar issues with any backed-up drive or cloud service.
I cleaned everything as per Avi Turner's great answer.
In addition, I manually deleted the \obj\Release -folder from my OneDrive folder and also logged to OneDrive with a browser and deleted the folder there also to prevent OneDrive from loading the cloud version back when compiling.
After that rebuilt and everything worked as should.
this happens because of the difference of names in the folder name and namespace name. If u create a namespace in a certain name , and later you rename it the namespace will have the old name itself. And the compilation will take the old path to find the .dll and .exe file . To avoid this open the .csproj file of each namespace with a text file , and find the old path in the file.
remove this, clean and rebuild the solution. This worked for me. I spent an entire day working on this problem.
I had this and managed to fix it using this SO answer:
Metadata file '.dll' could not be found
I had to uncheck all of the boxes, click Apply, reenable all of the checkboxes and then click apply again, but it fixed the problem.
I just ran into this issue and after an hour of screwing around realized I had added an aspx file to my product that had the same name as one of my Linq-To-Sql classes.
Class and Page where "Queue".
Changed the page to QueueMgr.aspx and everything built just fine.
For a new build, it could be that some dependencies aren't installed. For me it was Crystal Reports.
It happens when one project dll is failing and that is referenced by number of projects. So first fix it and then Build individuals.
I ve had this problem and it has started after importing our solution to TFS as a new project.I came across this topic and found a quick solution with some inspiration from your answers.
All i needed to do is to rebuild the project thats supposedly lost its metadata file and voila , problem solved.
There's also one another silly reason which you should check with patience... as it occurred to me after wasting 4hours searching for answers:
The story to me was that I accidentally changed a small line of code among thousands of c# class files and then trying to rebuild the solution. As you could imagine, I ended up with 40+ meta data file missing errors and with 1 compilation error among them -- which I didn't check carefully, purely thinking all errors were the same!
after 4 hours searching and then accidentally double checking my error list, I found that silly code error, fixed it, compiled, and then error disappeared.
Not a good answer to your problem, but do hope my case wasn't same to yours.
I had the same problem. In my case I had by mistake I had set all the projects apart from the project with the main method as console application.
To resolve I went to every project other than the one with main function and right click> properites > output type > class library
it was happened to me because I've a strange clash in the namespaces:
I had
AssemblyA
with namespace
AssemblyA.ParentNamespace
witch defines ClassA
and in the same assembly another namespace with name
AssemblyA.ParentNamespace.ChildNamespace
witch defines a different ClassA (but with the same name)
I had then in AssemblyA.ParentNamespace IInterfaceB witch had a method that in the beginning returns IEnumerable and a ClassB witch implements IInterfaceB
I had later modified the method in ClassB to return IEnumerable but I've forgot to update the IInterfaceB definition, so the method there was still returning IEnumerable
the fun fact was that the solution still complile if I did a rebuild all, but the tests witch refers AssemblyA didsn't work and returns the "Metadata file could not be found"error.
updating InterfaceB to correctly return IEnumerable as its implementor ClassB did solved the problem, unfortunately the error message was vague and also the fact that the compilation worked makes me suppose that maybe there is something to fix in the compiler
A coworker was running into this problem and the cause was eluding us. Eventually we realized that the project directory (and therefore the path to the NuGet packages) contained %20 (thanks, some Git gui tool which shall not be named) and the error messages showed that the compiler was looking for an very similar-looking path but one which had to %20, rather a space. Apparently something in the build system somewhere performs HTML-decoding on local filesystem paths.
Renamed the working copy directory and everything started working.
I had this issue too.
It started after I did a little folder tidying in my project.
I then tried to compile and got many duplicate class errors. (despite them not being duplicated. I think the linking was just out of wack)
Upon checking these, the errors would all disappear leaving only the "Metadata file ...debug\application.exe could not be found" error.
I solved this by looking in the build output window to find which classes were duplicated.
I would then right click the class name and "go to definition".
there will be two definitions to select from, open them both, the second definition will seem to open the same file again, however the second one will identify as the error source(red underline).
Delete all the code out of the file and save(This will not effect your actual file).
This should now compile correctly.
Ensure that there are no spaces in the path to your project...
I am using Windows 10 with Visual Studio Community 2019 and I was cloning a multi project solution as it was from a GIT repo. I was having this error with all other dependencies in the solution along with a E_POINTER error. Its path, inherited from GIT, had spaces like C:/repos/MY PROJECT NAME/ ...
I deleted it, cloned it again and make sure that its path contained no spaces like C:/repos/MY_PROJECT_NAME/ ...
That fixed my problem.
I had same issue too.
In my case, I recently add an internal class to somewhere in project. One of the dependencies in solution has same class name and both of them are added correctly to references.
I changed my last activity and rebuild, it works.
Be sure that your compiler messages are valid. In my case I catch reference error from there, not listed as an error in Error List.

The name '###' does not exist in the current content (wave of these on every page)

When any .cs page is opened a slew of "does not exist..." errors show up with an occasional "are you missing a using directive or an assembly reference?"
Although these errors appear, the project can build and run just fine. I can even step through the code. In fact when it is built the errors go away.
Once the run has ended, adding a new page will generate all the same messages for that page and any previous one opened that session.
I have done several searches but these error seems fairly generic and I have not found an answer that works for me just yet.
EDIT: A bit of elaboration on when it first showed up might help - My coworker made some changes by adding a brand new aspx page to our project while I fixed a code issue on a separate page. We used Source Safe go get his changes into my project. Ever since we used Source Safe it seems some configuration was changed with Visual Studio. Both our projects worked fine on separate machine, but now neither runs without these errors.
I have the same issue. I have VS2008 professional. After installing SP1, my copy of VS2008 now generates huge amounts of "does not exist" errors. The code is absolutely perfect, the errors are false reports. If I rebuild, all of the errors disappear. However, simply typing 1 character into any open .cs file will bring back all the errors. They do not go away after waiting.
Other people reporting this bug, say that double clicking an error makes it go away. Not the case for me however.
This is deffo a bug in VS2008SP1. It has to do with the background compilation not working or something. Anybody else have the same issue?
This might fix the issue:
http://blogs.msdn.com/b/kevinpilchbisson/archive/2008/10/30/hotfix-for-vs2008-sp1-available.aspx
Haven't tried it yet.
Anybody have this issue, clearly a BIG problem with VS2008SP1?
OK, I fixed it. I simply deleted the SUO file for my web project. The strange behaviour "seems" to have gone now for this project.
Before deleting the file I noticed that there were lots of breakpoints set up and each of these breakpoints had lots of "sub breakpoints". Don't know what that was all about, but it looked odd.
But deleting the suo file tidied all of this up. Breakpoints look OK now. Breaks and steps OK. Live semantic markup is OK. At least for the moment!
If you are getting issues, try deleting the suo file. Won't always work but is worth a try...

The name 'controlname' does not exist in the current context

I have a web application that I'm working on (ASP.NET 2.0 with C#, using Visual Studio 2005). Everything was working fine, and all of a sudden I get the error:
Error 1 The name 'Label1' does not exist in the current context
and 43 others of the sort for each time that I used a control in my code behind page.
This is only happening for one page. And it's as if the code behind page isn't recognizing the controls. Another interesting thing is that the IntelliSense isn't picking up any of the controls either..
I have tried to clean the solution file, delete the obj file, exclude the files from the project then re-add them, close Visual Studio and restart it, and even restart my computer, but none of these have worked.
I know this is an old question, but I had a similar problem and wanted to post my solution in case it could benefit someone else. I encountered the problem while learning to use:
ASP.NET 3.5
C#
VS2008
I was trying to create an AJAX-enabled page (look into a tutorial about using the ScriptManager object if you aren't familiar with this). I tried to access the HTML elements in the page via the C# code, and I was getting an error stating the the identifier for the HTML ID value "does not exist in the current context."
To solve it, I had to do the following:
1. Run at server
To access the HTML element as a variable in the C# code, the following value must be placed in the HTML element tag in the aspx file:
runat="server"
Some objects in the Toolbox in the Visual Studio IDE do not automatically include this value when added to the page.
2. Regenerate the auto-generated C# file:
In the Solution Explorer, under the aspx file there should be two files: *.aspx.cs and *.aspx.designer.cs. The designer file is auto-generated.
Delete the existing *.aspx.designer.cs file. Make sure you only delete the designer file. Do not delete the other one, because it contains your C# code for the page.
Right-click on the parent aspx file or Project menu. In the pop-up menu, select Convert to Web Application.
Now the element should be accessible in the C# code file.
Check your code behind file name and Inherits property on the #Page directive, make sure they both match.
exclude any other pages that reference the same code-behind file, for example an older page that you copied and pasted.
I had the same problem. It turns out that I had both "MyPage.aspx" and "Copy of MyPage.aspx" in my project.
Also, make sure you have no files that accidentally try to inherit or define the same (partial) class as other files. Note that these files can seem unrelated to the files where the error actually appeared!
I ran into this same error, except it was a WPF error. I was rearranging projects and had a control defined in like this:
<local:CustomControl Name="Custom" />
In my code behind I tried using Custom.Blah, but I got the error:
The name 'Custom' does not exist in the current context
What did the trick for me was changing my control in Xaml to this:
<local:CustomControl x:Name="Custom" />
Hope this helps someone out there!
I get the same error after i made changes with my data context. But i encounter something i am unfamiliar with. I get used to publish my files manually. Normally when i do that there is no App_Code folder appears in publishing folder. Bu i started to use VS 12 publishing which directly publishes with your assistance to the web server. And then i get the error about being precompiled application. Then i delete app_code folder it worked. But then it gave me the Data Context error that you are getting. So i just deleted all the files and run the publish again with no file restrictions (every folder & file will be published) then it worked like a charm.
I had the same issue, my problem was not having space between two attributes"
AutoGenerateColumns="False"DataKeyNames="ProductID"
instead of
AutoGenerateColumns="False" DataKeyNames="ProductID"
I fixed this in my project by backing up the current files (so I still had my code), deleting the current aspx (and child pages), making a new one, and copying the contents of the backup files into the new files.
this error often occurs when you miss runat="server" .
I had the same issue since i was tring to re produce the aspx file from a visual studio 2010 project so the controls had clientidmode="Static" property. When this is removed it was resolved.
I had a similar problem when tweaking with a Repeater after converting it from a DataList.
Problem was that I accidentally united 2 attributes when deleting an unneeded one.
<asp:Repeater runat="server" ID="ClientsRP"DataSourceID="ClientsDS">
.
.
.
</asp:Repeater>
And this prevented the generation of the repeater in the design file.
I had the same error message. My code was error-free and working perfectly, then I decided to go back and rename one of my buttons and suddenly it's giving me a compile error accompanied by that blue squiggly underline saying that the control doesn't exist in current context...
Turns out Visual Studio was being dumb, as the problem was related to the backup files I had made of my aspx.cs class. I deleted those and the errors went away.
In my case, when I created the web form, it was named as WebForm1.aspx and respective names (WebForm1). Letter, I renamed that to something else. I renamed manually at almost all the places, but one place in designer file was still showing it as 'WebForm1'.
I changed that too and got rid of this error.
1) Check the CodeFile property in <%#Page CodeFile="filename.aspx.cs" %> in "filename.aspx" page , your Code behind file name and this Property name should be same.
2)you may miss runat="server" in code
In my case I had to hunt through the 417 "controlname not found" errors to find an actual error: I had replaced a DLL but not updated the version number in the web.config. Fixed that and built successfully, 3 minutes after that all the other errors had resolved themselves.
Solution option #2 offered above works for windows forms applications and not web aspx application. I got similar error in web application, I resolved this by deleting a file where I had a user control by the same name, this aspx file was actually a backup file and was not referenced anywhere in the process, but still it caused the error because the name of user control registered on the backup file was named exactly same on the aspx file which was referenced in process flow. So I deleted the backup file and built solution, build succeeded.
I ran into this same issue. Apparently, you shouldn't call a class in the DLL the same name as one of the .aspx/.aspx.cs files. I thought they would not be in the same scope, etc. but it messed with Visual Studio's internal workings too much. I'm a bit surprised there isn't something to keep you from doing this if it is going to produce that type of error. Anyway, just delete the .aspx/.aspx.cs files and rebuild your project. Then bring them back in under another name. You can copy/paste your code into another editor if you don't want to retype it all back in.

Categories

Resources