Reputation: 3410
I have a form, MainForm, which was working just fine and dandy until earlier this morning. I made some code modifications to a different form and when I went to run the application, I received an error in MainForm (error is irrelevant).
I went into MainForm to see what the problem was and was horrified at what I saw... ALL MY CONTROLS WERE GONE. At first I panicked, but then had a bit of hope when I went into the MainForm.Designer.cs file and saw that all the code for the controls was still there.
So, the Designer file seems fine and yet the design view does not display any of the controls.
Has this ever happened to anyone before? Is my file corrupt? Is there anything I can do to fix this?
I do have a backup, but would prefer not to use it unless absolutely necessary as it is a day old and I do not want to redo my most recent work.
Thanks...
Upvotes: 1
Views: 2820
Reputation: 154
The last time I saw that, I did not have my my partial class Form as the first thing in the codebehind.
namespace WinForms{
public partial class MyForm : Form{
}
}
was like
namespace WinForms{
public class SomeClass{
//some code..
}
public partial class MyForm : Form { }
}
Upvotes: 0
Reputation: 11
I had the same issue... I opened up the designer.cs file and found that my Main Form code was quite a bit shorter than on a previous backup.
I copied the code from the backup (10 days old...) into my program, and I recovered most of my functionality in minutes. Another 5 minutes, and I was where I was before the error.
I then backed up everything - lit a candle to the God of Code, and prayed - "give us this day our healthy code..." I hope he is listening.
Upvotes: 1
Reputation: 10482
Try these steps:
Upvotes: 1
Reputation: 7996
Restarting Visual Studio has worked in a lot of cases for me in the past. Make sure you close all copies and check the list of running processes in Task Manager to make sure there aren't any copies running you don't know about. Restarting won't help in every case (if you really have a corrupted file) but it works a lot of the time for me.
Upvotes: 0
Reputation: 112855
Take a look at this page, listing some reasons why this might have happened, ways to prevent it, and how to recover.
Upvotes: 1
Reputation: 63126
You will want to take a look at what you did. Make sure file names match across the board, and that you didn't manage to accidentally re-name any of the individual files.
Also make sure that class names match across the board, between the 3 files.
Upvotes: 0