UI elements are not detected after renaming .aspx file and the class - c#

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.

Related

How to rebuild WinForm with just Designer file

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.

Visual Studio 2013 only builds HTML changes, not C# changes

I am building a personal website using asp.NET's webforms in visual studio 2013 express for web and am following this tutorial:
http://www.asp.net/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/introduction-and-overview
My page is structured exactly the same as in the website, I have changed some minor stuff to make it my own but the structure in terms of the C# classes and how the interact with the HTML are exactly the same.
I got to section 5 of the tutorial "Display Data Items and Details" and everything was working fine. I've used git a lot in the past so I decided to create a repository for this project so I can access it at work if I feel like.
Suddenly now when I make changes to the C# classes it won't build. It's even stranger because I if I make a change on an HTML file the change is built. In section 3 of the tutorial we learnt how to make the 'product' classes which are displayed on the products page. If I want to change one of the product names for example, when I build the change is not there. Simultaneously I went and changed some info in the HTML for the contact page, IT CHANGES when I build. Why wont the C# changes take effect when I build any more?
I am relatively new to both asp.NET and visual studio. The HTML changes when I build and the C# does not. When I change either I can see in solution explorer that there is a red tick for pending changes. Why would only the HTML pending change be included in the build and not the C#? How do I ensure that the build is actually building the version I see in my editor window?
EDIT
I do not know if I found the original cause but I found a solution/workaround. I realized that the classes mentioned above were grabbed by the html page from the page's database. The .mdf file for the solution was not being rebuilt whenever I cleaned and built so I physically deleted it and rebuilt the solution and voilla my C# changes occurred. I am still fairly new to this whole thing, can someone explain what the .mdf file does and why it wasn't being rebuilt?
Check your .cs files properties on the properties window in visual studio to make sure their Build Action is set to "Compile", Things that are not set to "Compile" do not get compiled. How MSBuild treats project items depends entirely on their build action. CS files default to "Compile" when you make them, but if you changed them yourself that would be why it doesn't update. Also CS files placed in the App_Start folder default to "Content" and they are compiled by ASP.Net when the Application Starts, so if you changed something in App_Start you need to reset the site.
Not exactly sure what is the problem, but I would do a right mouse click on the solution in Solution Explorer->Clean Solution, then do another build and see if that helps.

Help me undo (accidental)namespace rename in VS 2010

I did a bad thing, and I need help undoing it, because I don't know where to make the correction and don't want to further mess things up.
I have an ASP.NET MVC3 solution in VS 2010 with three projects.
In one of the projects, I have three folders, each with several files in them.
I realized that I mistakenly created a file in the wrong folder, so I dragged it into the correct folder.
After I did this, I renamed the namespace by typing in the right one, referencing the folder I just moved it into.
When I did that, the magic cursor, or whatever it's called, appeared under the new text I just typed in...so I hovered. It asked me if I wanted to rename from the old value to the new one I just typed in. So, I click yes.
I think a number of you already know what that means, but I hadn't a clue. Yes, I'm new at this. :)
All using statements in my solution referencing the original folder have been renamed in the process. The original folder is no longer available in any using statements I try to add.
Also of note, I had no clue what was doing this and thought my solution was corrupt or something, so I cleaned, and built, and rebuilt, and rebooted...so undo isn't an option.
What are my options for getting back to "normal" in my solution?
Thanks!
UPDATE, PROBLEM SOLVED:
All I had to do was rename the bad folder so I could create a new folder in the project with the bad folder's original name. I then moved the files from the bad folder into the new folder and corrected their namespaces.
Trashed the old folder.
Updated using statements.
Built the solution.
All is well.
I was afraid the rename went a lot deeper than it did. I'm not certain why this worked, but thank god it did.
Thanks to all who replied. I'll be exploring SVN this evening!
for example, you have tow folders named: Views and ViewModels in your project that named MyMvcProject; your namespaces will be MyMvcProject.Views and MyMvcProject.ViewModels;
and you rename the MyMvcProject.Views to MyMvcProject.ViewModels;
to undo, first exclude the folder named ViewModels - right-click on it, and select Exclude From Project; now open the find and replace window - Ctrl + f - select Quick Replace tab, in Find what textbox type .ViewModels and in Replace with textbox type .Views; set Look in to Current Project and click Replace All;
now must all ViewModels in project - not old viewmodels, because you exclude the ViewModels folder from project - be replaced with Views; now, include the excluded folder (ViewModels) and rebuild the project; if you got an error about namespace of any type, insert this using statement:
using MyMvcProject.Views;
regards.

Any way to make Intellisense work, when opening a cs file that's not part of the project?

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.

What could cause Visual Studio / C# error MSB3105: Duplicate resources

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.

Categories