Visual Studio Design View - form is empty

I have a C # project with two forms. Everything compiles well. When I start the project, all forms are drawn as expected.

A few days ago, in the design forms of all DesignView, nothing was shown, except for an empty form, for example, the one that you get in a new Windows.Forms project.

I reviewed a few questions about SO with a similar problem, here are comments on these questions:

  • there are no third-party libraries that my project uses (except for htmlAgilityPack, which does not cause this problem in other Windows CForms C # projects)
  • I checked that the InitializeComponent function only once in the project for each form
  • When I create a new project and add an existing form (i.e. one of my problematic project forms), the Design Viewer works as expected, so I suspect that the .cs, .Designer.cs and .resx files of my forms are OK.

Is there something that I could ruin in the project settings or somewhere else?

EDIT

The third paragraph above is misleading - I also tried to create a new project for the second form, and the problem remains. The minimum amount of source code that indicates the problem should be found here .

+5
source share
3 answers

Your project file has become invalid.

A valid project entry for the form is as follows:

<Compile Include="Form1.cs"> <SubType>Form</SubType> </Compile> <Compile Include="Form1.Designer.cs"> <DependentUpon>Form1.cs</DependentUpon> </Compile> 

At the same time, the DependentUpon line is missing, so the code and designer files are displayed separately in the project, and are not connected:

 <Compile Include="mainForm.cs"> <SubType>Form</SubType> </Compile> <Compile Include="mainForm.Designer.cs" /> 

If you added a missing line, the form displays correctly in design mode:

 <Compile Include="mainForm.cs"> <SubType>Form</SubType> </Compile> <Compile Include="mainForm.Designer.cs"> <DependentUpon>mainForm.cs</DependentUpon> </Compile> 

And to remove the resource file:

 <EmbeddedResource Include="mainForm.resx"> <DependentUpon>mainform.cs</DependentUpon> </EmbeddedResource> 

To fix this, you can simply edit csproj in the editor or do it in Visual Studio:

  • Back up files
  • Right-click the project and select Upload Project
  • Right-click the downloaded project and select "Edit [project_name] .csproj"
  • Make changes and close the file.
  • Right-click the unloaded project and select "Update Project"
+11
source

I solved the problem by deleting all files associated with this form

  • File → Right Click → Exclude from Project

and adding files back to the project

  • Project → Add → Existing item ...
0
source

Another opportunity. I had a group of forms, each of which came from a basic form. I added a save / restore location code - and everything was empty.

After an hour with its launch and the inability to find something wrong, he suddenly started throwing a null reference exception in the constructor, and not just being empty. Duh - the save / restore code used an object in which there was no development time.

Why he was silent about this, and then suddenly started screaming, I have no idea.

0
source

All Articles