I'm currently developing an app with Mono, I recently updated to Xamarin Studio 4.0.8, and was having problems with the design elements not being added to the solution.
I tried to edit manually the designer.cs, and later on I erased it, hoping the program will regenerate it again, with the layout changes.
I have tried:
Rebuilding it
Cleaning and rebuilding
Erasing the file through the file explorer
And it still doesn't regenerate properly, Xamarin creates the Resource.designer.cs but it's empty, and when compiling it returns this:
Error CS0103: The name 'Resource' doesn't exist in the current context (CS0103)
Help please...
Lots of time having this issue. What i did:
Remove "resources.designer.cs" using Xamarin (secondary button->remove).
Go to command line (finder on Mac/Explorer on Windows) and delete manually the file (be sure you deleted it).
Go to Xamarin, clean->build (this will regenerate the resoruces.designer.cs).
As you remove the file from the project, you have to add it again. secondary button over project-> add Files->select Resources.designer.cs (tipically on /Resources folder).
Make sure the "Build Action" of the Resource.designer.cs file is Compile (sometimes it takes a different build action by default).
Clean and build.
At least it have worked most of the time.
I had this happen a while back. If you right click on your XML file, and click properties. Make sure that the Build Action is set to "AndroidResource"
If I recall correctly that fixed it
This work for me:
Open your .designer.cs file and erase all class content, letting only the class declaration empty.
open .xib file or storyboard that give you trouble with your .cs file.
update Identify>Class property of the view that use that .designer.cs class removing, unfocus, focus and setting again the property value.
save
rebuild
Related
I just downloaded Visual Studio and created a new Xamarin.Forms project. However, when building the app with the auto-generated code I got stuck on the following error in the code-behind of MainPage.xaml:
The name 'InitializeComponent' does not exist in the current context
I looked up solutions on the internet but did not find one that works for me.
What I tried:
Changing the custom tool in the properties of MainPage.xaml (which was empty beforehand)
I checked if the namespaces match (they do)
I tried saving all the files
Here is an image of the auto-generated code, which I didn't edit:
If you are having successful builds, but a nagging initializecomponent does not exist error,
CLOSE VS,
DELETE the hidden .vs folder in your project (this clears intellisense).
OPEN VS - the error is gone.
I've had this issue crop up here and there where InitializeComponent and a number of other classes and methods "does not exist in the current context". Not sure of the underlying problem, but if it is the same as I've had, I unload and reload all projects. This can be accomplished by right clicking on the project in the solution explorer, clicking unload, right clicking again, and hitting reload.
I had also this problem sometimes when creating a new page, make sure that the BuildAction of the page is set to "Embedded resource" as other normal pages
This is what I did to remove the error on my Xamarin project. I closed the project and removed obj folders. Then reloaded the Project again and the error disappeared.
Check the ContentPage property of your XAML file. Make sure that the x:Class value, is correct, example: x:Class="YourProjectName.Views.ContentPageName">
I created a ContentPage and then renamed it, but the x:Class wasn't updated, so I had to do it manually. Tried first unload/reload but didn't work in my case.
In one case also, I created a content page with the name 'Buttons' and had the same issue. I deleted it and created another one with the name 'UsingButtons' and was ok. Maybe there are reserved words for file names.
So I am new to Xamarin studio and have been stuck on a little bit of a frustrating issue. Every time I make a change within the resources file, the Resource.designer.cs file does not regenerate and recognize the new changes. Does anyone know how I can update the changes so that I can interact with newly added widgets? I appreciate the help.
Check your Android's .csproj file and make sure the following AndroidResgenXXXX properties are included within a PropertyGroup (within the Project)
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
I have been working on c# Gui for about a week without problem, all of a sudden when I added a label control I tried to access its events and saw the error "This document item has no code behind file. Add code behind file and a class definition before adding event handlers"
This is odd since the gui/methods still runs fine but it is making it very difficult to progress...any ideas? Did a file get deleted etc? Can provide more info on request, thanks for the help!
(couldn't add screen shot unfortunately yet but error is displayed in properties window/event tab)
I encountered the same error"This document item has no code behind file. Add code behind file and a class definition before adding event handlers" in my first C++ Helloworld project when I try to add a even handler for one button I added in the MainPage.xaml.
I solved the problem by restart Visual Studio 2015 and recreate a new project, then I add a even handler for the button successfully.
It's my experience and just be posted here that maybe you can use it as reference.
I ran into this, too. In my project, most UserControls were fine, but there was one group that showed the "no code-behind" message instead of properties. The .cs files did exist, though. In the Solution Explorer tree, the xaml files all had xaml.cs files. I checked the csproj file, and all the xaml.cs files were tagged as <DependentUpon> the correct matching xaml file.
I was able to fix this by closing the solution, then deleting the csproj.vspscc (Source Control Project Metadata) file for the project. When I reopened the solution, that metadata file was rebuilt and the Properties were available in Visual Studio again.
We have a SQL file that's an embedded resource in our solution. When the sql file changes, and we click debug, the solution doesn't rebuild the project with the embedded resource if no actual C# code has changed.
I've had this issue with other solutions as long as I can remember, and I personally know to do Build Solution to make sure it gets built...but this has become an issue for a number of new developers who can't remember to do this and get confused when their changes to the SQL file aren't reflected at debug time...so I was wondering if anyone knows an easy fix.
The easiest fix is to "rebuild" instead of "build". Other people will "clean" and then "build" to be 100% sure.
Embedded Resources are not updated in the debugging DLLs unless the output DLL is truncated, which can only be guaranteed to occur with rebuild and clean.
Unfortunately, a clean and rebuild does not seem to always work for Resource files. My issue was with a string resource file, and how I fixed was as follows in VS2016:
Close .resx and .Designer.cs if they are open in the IDE
Delete .Designer.cs class (right-click, delete in solution explorer)
Double click .resx file in solution explorer to open
If required, change 'Access Modifier' from 'Public' to 'No Code Generation', and save
Change 'Access Modifier' from 'No Code Generation' to 'Public', and save
=> the .Designer.cs code should then update
I ran into the same issue with VS2017.
This is what worked for me:
Open the .resx file. Make sure you are in the Resource editor, do not use an XML editor since sometimes changes done there will not trigger the generation of Designer.cs
Make sure Designer.cs is not open.
Do a small change, save
Undo the change, save
I have the following problem.
I made an application in C# (using Visual Studio 2010). Everything worked fine.
Then I had to make some changes in a "main.cs". Did those... all fine again.
Then I had to make other changes in same file. Did those... cleaned the solution built it. The problem is that when I run/debug/anything the application I get the same result as I did before I made the changes. I even tried to break the code (called a random function that didn't exist, used wrong syntax), but the result was the same "Build successful" and the old version.
Is there some kind of cacheing mechanism or something? How do I get rid of this problem?
I added prints for the "compile" solution... I can't find the build property.
Try deleting the bin and obj directories in the Visual Studio project directory. The obj directory contains the temporary files used to create the binary while the bin directory contains the binaries for that project. In addition, check if there are any warnings being shown when you build your solution.
I was able to reproduce the same error i.e. build successfully even though the file has not been compiled. The Build Action of the file had not been set to Compile.
The correct Build Action for a code file (main.cs) would be Compile.
According the updated question the file properties does not have the compile option
The reason for this is that the file (main.cs) has not been included in the project, but the "Show all files" button is "on" in the Solution Explorer. The file has not been included in the project (hence not compiled) and the file icon is greyed out in Solution Explorer.
To include this file in the project, right click on add existing item to the project (see following image). In the subsequent dialog select the file (main.cs) and click on the add button.
This should solve your problem.
In future, it is best to keep the "Show All Files" button as "off" to avoid confusion.
Is it possible you have selected the build and run last successful version? Check out my answer to something similar here. If the changes you made broke something and you had checked the boxes and hit yes to the dialog boxes in my answer below then that's most likely the issue.
Cannot see changes I make when I run my application in Visual Studio
Make a backup of your solution.
Delete the .cs files from within the solution explorer. If your program compiles and runs, than you are linked to source folders and not actually using the one in your solution.
I doubt this is it, but worth a try. The other things that came to mind you have already eliminated out with the previous answers.