Try changing this
Inherits System.Windows.Form
to this
Inherits System.Windows.Forms.Form
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
After being advised to switch my app's "DotNet" Framework from 3.5 to 4.5.2, the ".Designer" is now loaded with errors and I can't display my app in Design View.
Going back to 3.5 didn't help. "Rebuild" didn't help.
How do I undo the damage so I can get my program working again? :(
Two options
Thx for the reply.
As noted in my question, going back to 3.5 (Project | Properties | Application | Target Framework) didn't help.
I'm not sure how to restore using the GitHub repository (Under "Git", there's "Local Repositories" but I don't know what to do next.)
(My reply did not appear so excuse this reply if a dupe.)
Going back to 3.5 didn't help. I'm not sure what to do under "Git" to recover my original/working code.
Try changing this
Inherits System.Windows.Form
to this
Inherits System.Windows.Forms.Form
Thx for the reply. Changing "Inherits System.Form" to "Inherits System.Windows.Forms.Form" made no difference. :(
My code doesn't have "Inherits System.Windows.Form"
Hi @Mugsy's RapSheet ,
Try creating a new .NET Framework 4.5.2 project, compare the differences in designer.vb file formats between the two, and then modify where the error is reported.
Thx for the reply.
I've been saving "Create a new project and dupe the code" as a last resort. I'm hoping there's an easier way to get "Design View" back for the form.
It really shouldn't be this much trouble (it REALLY should have never happened in the first place!) :(
In regards to reverting changes to a file see how to revert changes to a single file. In Visual Studio, pulling up history, right click on a file and select revert. In GitHub desktop (which is what I use), select history, find the last good commit, right click and select revert changes in commit.
I followed the link on How to revert changes. It begins with "First you need to go to the shared repository on GitHub". Already I'm lost. I don't think a "Repository" was ever created or exists.
Under "Git" on the VS toolbar, the top 3 menu items are "Clone Repository", "Create Repository", and "Local Repositories | Open Local Repository" (which only shows empty folders.) I'm not finding a "History" anywhere.
The "Solution Explorer" tree lets me open another form in my project (frmSettings.vb) in Design View (b/c it does not contain any errors), but my "frmMain.vb" can only be displayed as code (I assume until the errors created by the DotNet conversion are fixed.)
In Solution Explorer, try right clicking on a file to revert, select Git then Undo Changes.
Thx for the follow-up, but "Git" is not listed as an option.
It doesn't look like you're storing your project on Git, and Visual Studio itself doesn't offer the ability to restore historical versions of your project.
Crud. I didn't even know that was an option.
Looks like a manual rebuild (via reading the Designer file script in Notepad++) is my only choice.
Thx.
PS: Is anyone else aware of the potential disaster simply from changing the Target Framework in Properties? That's nuts.
@Mugsy's RapSheet I created a VB Winforms project in an XP VM using VS2005. The VM used to create the project had .Net Framework 2.0 installed.
Then I moved the VB Winforms project to a Win10 System which has .Net Framework 4.8 and VS2022 installed.
When the VS2005 created project was opened in VS2022 this dialog was displayed -
I clicked the OK button and VS2022 upgraded the project. I opened the project properties after the upgrade as seen here -
Note that the Target Framework dropdown is blank. The Win10 system doesn't have .Net Framework 20 installed and VS2022 doesn't target that old Framework version. I instructed VS2022 to Target the .Net 4.8 Framework and this warning was issued -
After VS2022 retargeted the project I opened the Form in the designer -
And the a successful build was performed.
Finally, the VS2022 Project Upgrade process backed up the original files in a newly created Backup folder -
I experienced exactly the same thing upto the "target framework change".
After which, the Designer code was transformed in a manner such that it now reported 40 errors (see original screenshot) that prevented the form from being opened in Design mode.
My original app was written to be compatible with XP with a Framework of 3.5. Changing it to 4.8 broke it and I have no idea why.
(Why is it my replies never appear until after a second post?)
In this and other threads you said that you updated the target framework to 4.5.2, not 4.8. And I never suggested updating the target framework to anything other than 4.8. The Inherits statement specifying System.Form is clearly an error. Even the code generated by VS2005 contain the correct statement. I believe there's something wrong with your project that goes far beyond anything that could have been done by upgrading the target framework.
I was going off memory when I typed "4.5.2". When I checked, I noticed it was 4.8.
Does it matter? Is there a reason switching from 3.5 to 4.5.2 would be less likely to create a problem than switching to 4.8?
(Note: As far as I'm Aware, the original Designer code used "Inherits System.Windows.Forms.Form". I don't why the conversion changed it to "System.Form", but changing it back didn't fix the problem.)
Contradictory information just confuses the issues. As I see it the operative issues relate to erroneous code such as the Inherits statement as well as any coding errors that we have not seen. Finally, I suggest you double check that the project references properly point to the 4.0 assemblies.
There shouldn't be any "coding errors" in an auto-generated "Designer" script.
I checked my other projects and can't find a single instance of "Inherits System.Form". I'm confident that code was changed in VS's conversion process (which was simply me changing the Project | Properties | Target Framework from 3.5 to 4.8 from the dropdown menu.)
Well, Visual Studio didn't change the Inherits statement in my example when importing the project or changing the target framework. What about the project references? Have you checked them?
What reference would change "Inherits System.Windows.Forms.Form" to "Inherits System.Form" (particularly when doing so breaks the form?)
And would reestablishing that reference fix the code and make it work again? If not, there's point in pursuing it further.
I've already begun the process of recreating the form based on the recorded Designer values.
Since you said that correcting the Inherits statement did not solve the problem then the problem must be elsewhere. All I can do is suggest things for you to check, like the project references. If you'd rather recreate the form that's fine with me.
I do not know what you mean by "project references". I don't believe there are any.
Be specific.
Open the Project Properties and select References. You should see something similar to this -
And what? What am I looking for?
And what? What am I looking for?
Any indication that there is an error. Cannot find a path. Bad version number. Missing reference to System.Windows.Forms assembly
Everything appears to be in order.
All the references are incorrect. They are pointing to the wrong versions.
First, go to project properties and verify that the Target Framework is actually 4.8
If the Target Framework says 4.8 then remove the incorrect references and and replace them with the equivalent version 4 Framework assemblies.
I had gone back to 3.5 to restore/repair my code.
Switching the Framework back to 4.8, all references changed to 4.0 and the code is broken again (29 Errors. frmMain won't load.)
Going back to 3.5.
In the initial post you wrote "Going back to 3.5 didn't help. "Rebuild" didn't help." I'm totally confused now, but as long as you're happy...
"Going back to 3.5" did not undo the damage of the conversion. But prior to that, my program operated just fine. THAT is why I decided to recreate the form with the original (3.5) Framework.
"Happy" is not a word I'd use here.
Try changing this
Inherits System.Windows.Form
to this
Inherits System.Windows.Forms.Form
Thx for the reply. Changing "Inherits System.Form" to "Inherits System.Windows.Forms.Form" made no difference. :(
My code doesn't have "Inherits System.Windows.Form"
In the picture above you do.