Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Design View - form is blank

I have a C# project with two forms. All compiles well. When I run the project, all forms are drawn as they are expected to.

A couple of days back, the DesignView of all forms started to shown nothing but a blank form, like the one you get in a new Windows.Forms project.

I went through several questions on SO with a similar problem, here are the comments to those questions:

  1. there are no 3rd party libraries that my project uses (apart from htmlAgilityPack, which does not cause this problem in other Windows.Forms C# projects)
  2. I have checked that the InitializeComponent function is only once in the project for each form
  3. 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 - hence I suspect that the .cs, .Designer.cs and .resx files of my forms are OK.

Is there something I could have messed up in the project settings or somewhere else?

EDIT

The third point above is misleading - I tried creating a new project for the second form as well and there the problem persist. The minimal amount of source code that shows the problem is to to be found here.

like image 652
Daniel Bencik Avatar asked Aug 20 '15 09:08

Daniel Bencik


2 Answers

For those searching around and finding no solace, I have another solution. The project I inherited has horrible code quality and the previous developer had mixed case all over his code because "It's case insensitive, so it doesn't matter"

So, while PopulateRevs is, in fact, identical to POpulateREvs in Visual Basic, that kind of laziness leads to issues. To wit:

<Compile Include="Inventory\Partmaster.Designer.Vb">
  <DependentUpon>Partmaster.vb</DependentUpon>
</Compile>
<Compile Include="Inventory\Partmaster.vb">
  <SubType>Form</SubType>
</Compile>

I happened to see this in the .vbproj file while looking at other solutions that didn't work. I happened to change Partmaster.Designer.Vb to Partmaster.Designer.vb (lowercase extension) and it worked.

So as another solution, while Visual Basic is not case sensitive, it looks like the .vbproj file is. If you're stumped, another thing to make sure is that your file names and .proj files share the same case.

(I realize this is tagged C#, but I tested this in C# and the mixed case will cause problems there as well.)

like image 150
JohnMetta Avatar answered Sep 22 '22 03:09

JohnMetta


Your project file has become invalid.

A valid project entry for a form looks like this:

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

Yours though is missing the DependentUpon line - which is why the code and designer files appear separately in the project, instead of being connected:

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

If you add in the 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 tidy up the resource file:

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

In order to fix this, you can just edit the csproj in an editor, or to do it in Visual Studio:

  1. Back up the files
  2. Right-click the project and choose "Unload Project"
  3. Right-click the unloaded project and choose "Edit [ProjectName].csproj"
  4. Make your changes, and close the file.
  5. Right-click the unloaded project and choose "Reload Project"
like image 35
stuartd Avatar answered Sep 18 '22 03:09

stuartd