views:

195

answers:

1

I'm currently using Microsoft Visual C# Express Edition (with SP1) for a Project. I'm getting some strange errors in the Forms editor when editing one particular form, the message reads:

Type 'System.Windows.Forms.Control' in assembly 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

and it apperars on trying to save the form. It mostly appears 3 to 5 times consecutively but sometimes also pops up every few seconds nonstop, until I kill the application.

I believe it starts when I tried to add some Application-Settings, but I can't seem to reproduce it.

Any ideas how to spot the error would be appreciated, thank you.


Edit: Saving the form means clicking the "Save" Button in Visual C# Express. I am not trying to serialize it manually, the error pops up while editing the form in the IDE.

Edit: Here is a screenshot - This pops up when I save the form.
http://img10.imageshack.us/my.php?image=notserializable.png

+1  A: 

The Windows Forms designer serializes your form as you edit it, inside the .Designer.cs. That's why you often see the error as your edit your form.

Usually, you edit classes deriving from UserControl or Form in the designer. Your error seems to indicate it's trying to serialize a Control. Did you change the base class of MainForm to Control?

Or did you edit the MainForm.Designer.cs file manually? I strongly recommend not editing the .Designer.cs file directly because if you do, it's really easy to break the Windows Forms Designer support.

Anthony Brien
The base class of my MainForm is "Form".I may have (more or less) accidently changed the MainForm.Designer.cs file. I could try to delete the form and recreate it manually to see if that changes anything. Are there any other possibilities?
dasmaze
If you have embedded your own custom controls into this form, and these controls cause exceptions when they are constructed, it can break the windows forms designer. One way to spot to spot those errors is to debug devenv with another devenv! If your code is at fault, it'll break in your code.
Anthony Brien