0

I have an application where I would like to have two releases, one releases will have everything enabled, in the other release certain menu items will be disabled. I tried creating a new solution configuration where certain menuitems are disabled. My code is the following:

#if (SMART == true)
        Download_Menu.IsEnabled = false;
        ChangeLayout_Menu.IsEnabled = false;
#endif

This however breaks the program.

Given error:

An unhandled exception of type 'System.BadImageFormatException' occurred in WindowsBase.dll Additional information: Could not load file or assembly 'VirtiumStorAPIWindowsManaged, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format

This is my first time trying this so any suggestions would be great.

so if I use the following code it works in Debug mode:

#if DEBUG
        Download_Menu.IsEnabled = false;
        ChangeLayout_Menu.IsEnabled = false;
#endif

how would I get this working in a custom solution configuration?

yawnobleix
  • 1,204
  • 10
  • 21
  • "breaks the program" is not particularly descriptive! What breaks, how does the break show itself? We're not mind-readers – freefaller Jun 18 '13 at 16:39
  • the following error is given: An unhandled exception of type 'System.BadImageFormatException' occurred in WindowsBase.dll Additional information: Could not load file or assembly 'IWindowsManaged, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format. – yawnobleix Jun 18 '13 at 16:40

3 Answers3

1

Your have got something wrong. Better write:

#ifdef SMART
        Download_Menu.IsEnabled = false;
        ChangeLayout_Menu.IsEnabled = false;
#endif

Read more here

And the MSDN Preprocessor Directives library site.

Community
  • 1
  • 1
  • the problem is not related to the precompiler directive syntax. I've already experienced the related problem. Please see my answer for further information – Luis Filipe Jun 18 '13 at 16:55
  • so I decided to try and compile in debug mode with the following code so it won't have the problem Luis mention. My new code is: #if Debug Download_Menu.IsEnabled = false; ChangeLayout_Menu.IsEnabled = false; #endif but this still doesn't disable the menu items – yawnobleix Jun 18 '13 at 16:58
  • If i understand, your code now compiles and the assembly is correctly loaded at runtime, right? try wonko79 syntax – Luis Filipe Jun 18 '13 at 17:55
1

That is because the two configurations are not compiling to the same CPU type.

Whether select "Any CPU" or 32bit ou 64bit

Luis Filipe
  • 8,488
  • 7
  • 48
  • 76
0

It happens because your project configuration is wrong for the new preprocesor directive that you create. Make sure the solution configuration and platform target for the new preprocesor directive matches with your debug configuration. One practical example why you face the bad image format exception is that in your project you might be referring a assembly which is built with 32 bit (x86) configuration and your project might be getting built with 64 bit (x64), so when this project tries to load the referenced type (i.e 64 bit assembly trying to load 32 bit assembly) it will cause badimage format exception.

srsyogesh
  • 609
  • 5
  • 17