3

I'd like to exclude / include a complete form in my project. But when I add the needed #if CONST and #endif the compiler complains about resources that may get wrong names.

warning MSB3042: A namespace or class definition was found within a conditional compilation directive in the file "Form1.cs". This may lead to an incorrect choice for the manifest resource name for resource "Form1.resx".

What does this mean?

And how do I fix it?

H H
  • 263,252
  • 30
  • 330
  • 514
Simon Ottenhaus
  • 715
  • 2
  • 8
  • 19

3 Answers3

4
  • Explanation: A normal Form (created from a Template) consists of 2 .cs files and a .resx file. By eliminating the Form1 class you 'orphan' the resources.

  • Workarounds:

    1. Make a simpler Form without resource file.
    2. use a #else tag to create empty stubs for the Form1 class
    3. Forget about the idea and only eliminate the (few) points where the rest of the program uses the Form.

I favor 3, what benefits do you expect from removing the Form?

H H
  • 263,252
  • 30
  • 330
  • 514
  • There will be two versions of the program. Due to safety reasons some Forms (and functionality) should be excluded in the deployment version. So 3) is not a solution for me, because the Form still exists in the .exe. – Simon Ottenhaus Dec 17 '09 at 11:26
  • Ps: workaround 2) solves all problems. There are no more warnings, even the designer works with the stubs (when reopened). – Simon Ottenhaus Dec 17 '09 at 11:32
0

If you did not set images and you don't use the resx for translations (i.e. your form is not localizable) try to remove your Form1.resx.

jmservera
  • 6,454
  • 2
  • 32
  • 45
0

Move your #if CONST / #endif region, so that it is within the derived form class declaration encompassing the entire contents of the partial class in Form1.cs. The default constructor will takeover, and your warning will go away.

Jim Fell
  • 13,750
  • 36
  • 127
  • 202