Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
When I added a class just above the form class my form designer not loading it showing error as given below as in call stack

Hide Call Stack

at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)


My code is like this :

C#
namespace WindowsFormsApplication1
{
 public class myclass
 {
    int mymember;
 }
 public partial class Form1 : Form
 {
    public Form1()
   {
            InitializeComponent();
    }
 }
}


where ever I comment the myclass I am able to see windows forms design. when I uncomment this it shows error again in showing the design.

Do any one knows why happens like this???

Thanks in Advance.
Posted
Updated 18-Dec-18 18:04pm
Comments
Sergey Alexandrovich Kryukov 10-Aug-15 2:32am    
Are you saying that if you remove 4 lines, the definition of myclass, the application starts to work and the form start to show in the designer?
If this is so, I cannot see a reason for a problem in this fragment of code. I would advice one thing: don't abuse or overuse the designer. I try not to minimize adding any code in this file. This is a partial class, so you can add you code in another file...
—SA
DamithSL 10-Aug-15 2:39am    
sreeyush sudhakaran 10-Aug-15 2:54am    
this solution works,i tried but may i know what is the reason behind this?
DamithSL 10-Aug-15 2:57am    
it seems bug in Visual studio
sreeyush sudhakaran 10-Aug-15 3:02am    
ok..thank you, I came across same scenarios when i was doing a conversion project from vb6 to vb .net also that time unsupported controls made the bugs but here it looks strange , nothing just a class causing trouble.

I hope visual studio needs something like this

"The class Form1 can be designed, but is not the first class in the file. Visual Studio requires that designers use the first class in the file. Move the class code so that it is the first class in the file and try loading the designer again."

In VS 2013, you get an error message when you try this:
The class frmInformation can be designed, but is not the first class in the file.  Visual Studio requires that designers use the first class in the file.  Move the class code so that it is the first class in the file and try loading the designer again.
There is a good chance that you get this message as well.

It's a restriction on how the VS designer works, is all. Embed your new class within Form1 or add it at the end of the file instead of the start (or better, put it in it's own file so it is easy to find)
 
Share this answer
 
Comments
sreeyush sudhakaran 10-Aug-15 3:06am    
Yea..I realized it :)
NimaRayan 5-Sep-19 8:07am    
I had such a problem and after reading this solution it resolved!

Thank you
OriginalGriff 5-Sep-19 8:14am    
You're welcome!
The problem is because you add some class above the form1 class or whatever your form name. to resolve this error you need to add classes which you want to add below the form class.
 
Share this answer
 
Comments
CHill60 19-Dec-18 4:49am    
No different to Solution 1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900