I recently picked up a project of mine from a few months ago that I had stored on Github. However, there are a number of forms that apparently did not get stored in the repo. I'm not sure how that happened, but I'm trying to recover as much as I can.
For example:
- CreditsBox.cs
- CreditsBox.Designer.cs
In this case, the CreditsBox.Designer.cs file exists, but the CreditsBox class file does not. Fortunately, the forms that this happened to didn't have too much login in them, so its trivial to rewrite. However, it would make it 10x easier if I could somehow rebuild the form with just the designer file?
Any help is appreciated!
The designer file is all you need to re-create the UI of your forms.
You could follow these steps
Create a new Project.
Add a form and name its file as CreditBox.cs.
Use your saved designer file to replace the one created by Visual
Studio.
As far as I know, the last step could be done also with Visual Studio open but, in any case, better close VS and reopen it afterward.
Of course you could do the same for all other form designer files with the missing main cs file.
So I found a somewhat easy way to fix this.
Create a backup of the .Designer.cs file and delete the original from the project. Then, create a new form in your project with the original form's name (so dependent methods/calls don't fail). Then go through your original .Designer.cs file and create the objects simply by dragging from the Toolbox onto the form and naming it to match the original file. Once you have all of them added (don't worry about styling), copy the old Designer.cs content back in so it will fix the styling, spacing, and all that. Once you build, the designer will update to the original styling/spacing/etc.
Related
I was working on a project in ASP.NET and I needed to rename the .aspx file. So I did that and noticed that the class name hasn't changed. I did the standard Ctrl+R twice trick and got a message saying that it hasn't been renamed everywhere. Ctrl+Z didn't help and trying to rename it back to what it was also didn't help. Now throughout the whole file Visual Studio complains that elements such as Tables and TextBoxes don't exist. Is there a way to fix this without making a new project from scratch and migrating all the files?
You can use Ctrl+Shift+H over the entire project (or solution, if need be) to rename your old-class-name to new-class-name. This will allow you to rename what has not been renamed without having to recreate your project from scratch. I suggest that you review each rename one-by-one (which the Ctrl-Shift-H function allows you to do) rather than blindly renaming everything without review.
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
This might sound extremly strange, but i have no idea what to do.
Visual studio 2008
c# windows form
I've been working on a project for a while, and it's all been rosy. Now, anything i add to the windows form in terms of labels, picturebox's ect don't appear at runtime. They are visible in the designer view, but do not appear at run time. Now, even when i move things that were already there, they don't move at runtime.
I'm guessing this is the cause of a windows update messing with visual studio again, but i can't find anything on the problem
Just a note, The project runs exactly how i left it yesterday every single time. Regarless if i move objects, add labels.
Anyone know of anything like this, know of a fix.
Thank you
I think you should Clean your solution and then rebuild it.
As you are using Express Edition, Clean option might not be added by default.
Go to Tools -> Settings and Select "Express Settings".
Now go to Tools -> Customize. And select Commands tab in the dialog.
In the dropdown next to Menubar radiobutton, select Build.
Click on AddCommands and add "Clean Solution".
Now you can go to Build -> Clean Solution. And then rebuild the project.
One time, I found the .suo file of the solution corrupted for unknown reasons.
Delete or rename it, then try again ?
The designer for classname.cs rewrites classname.designer.cs. View the code of the designer.cs and see if your changes are actually being saved into this file. Try hand-editing this file (change a label string or something else easy to spot at runtime).
Maybe the designer.cs file is read-only or perhaps there is a design-time exception that prevents saving the new .cs. I have run into issues like this when I had third-party component libraries in a project and the third-party designers were crashing.
Did you perhaps remove the call to InitializeComponent() from your Form class constructor?
What we ideally need is, to know how Microsoft handles XAML generated code (Those *.g.cs files). If you goto a XAML code behind, intellisense will work even if the *.g.cs file is not part of the project!!
Context:
In a custom VS package, we need to have some logic to open a CS file (with out making it a part of the project) in the VS IDE, to allow the user to edit it.
We are hooking up the document to the Running document table and receiving the events like Saving, Close and all, using IVSRunningDocumentTable. Works good.
Now the problem is, when the document is opened, Intellisense can't work, for the simple reason that the opened document is not part of the project (sadly, we can't do that, we can't make it code behind).
Intellisense is driven by a memory cache of identifiers and types. These types are cached based on the project you are in and the references that project has. If the code file you are editing is not part of a project, Visual Studio would have to load every possible assembly and create intellisense data for each type in the entire .NET framework because it would have no way of knowing whether or not your code file required it.
I guess Visual Studio could load intellisense based on the content of the file but that is not the way it currently works.
Visual Assist X by Whole Tomato is an addin to VS I've been using for many years. It will give you Intellisense and more when you open it.
While working on an existing project I suddenly got the following error when trying to compile the solution:
error MSB3105: The item "[filename]" was specified more than once in the "Resources" parameter. Duplicate items are not supported by the "Resources" parameter.
Now, as far as I'm aware, I did not make any change to the project that affects the resources. Also I have checked each and every file within the project, but there is no duplicate reference anywhere to this file.
Now I already found some forum entries regarding this error:
1) Open the .csproj file and remove the duplicate reference. [Tried this, but I cannot find any duplicates in it]
2) In a 'partial class' project, move everything to a single class. [ Could try this, but the project has been split up into partial classes since the start, and I do not want to change this just because of the error ]
So what else could cause this ?
Did you try showing all files in the Solution Explorer? You could have a duplicate .rsx file somewhere in there.
I found the answer in .NET forum posting by Roy Green, and Theresa was right after all, though I did not recognize it.
If you have your main form class split up into partial classes, the partial sections end up in the solution explorer as separate items. And if you double click on them they show up in the designer mode as a normal form. But if you (accidentally) drop a control on these forms, Visual Studio creates a new .resx file and a InitializeComponent routine for it. But since this form is actually just part of the Main Form class it leads to the 'duplicate resources' error. And there is no other solution but to remove the InitializeComponent routine and delete the .resx file by hand.
Be sure that under yourForm.cs no duplicate resources are defined (.resx). If you renamed your Form, remove the old resource because the new one during compile will be created with the new name.
I just made the same mistake. Delete the mainform.designer.vb, then I restored it again from the recycle bin, and found this error message when compiling.
I try to search on google and someone suggested to check on .vbproj. Did that and found a duplicate on some line.
I had this as well, in VB. There is the "real form" file frmMain, and then I had created new class files and modified them to be Partial Public Class frmMain. For example, I have an ImportFromExcel.vb Partial Class file (I didn't want to clutter up the frmMain.vb with the rather complicated Excel import code.)
Everything worked fine until I decided I wanted to use an OpenFileDialog in the Sub ImportFromExcel. I dragged the OFD from the toolbox over to the Designer view of the ImportFromExcel file. (I have no idea why this view exists, if you can't do anything with it!) But at any rate... dragging the OFD to the Partial Class Designer created an ImportFromExcel.resx file. The drag/drop operation also created an InitializeComponent sub in ImportFromExcel, which is redundant and shows an error -- easily corrected with a little editing.
Ultimately, I chose to not use the dragged resource, but localized the code in the ImportFromExcel.vb file.
All you really have to do is right-click the ImportFromExcel.resx file, and choose Delete. Everything else seems to "fix itself", and it builds fine now.
In my case, this problem happened because a file had the same name but not the same case in the GIT repository.
For example MyFile.cs and myFile.cs.
If you do a checkout on windows, one of the files is overwritten by the other (no message, no warning). So, it is compiling, and we don't notice anything. But if you try to compile on Linux (with .NET Core) both files are present, and there is this error at compile time.