Reputation: 3505
I have a strange issue
#if (!DEBUG)
checkLicense();
#endif
This is working correctly in both Release
and Debug
configurations. But when I try to publish using release configuration this condition does not execute. It looks like publish is using the debug dll.
What have I missed?
Upvotes: 7
Views: 1840
Reputation: 6517
Alternative to my other answer because I just noticed the mvc tag, whereas before I assumed you were using WebForms.
Is the code snippet you provided by any chance in a View?
Because if that's the case, then the DEBUG setting for your project is not going to be respected when the View is generated at runtime - it will only respect a debug flag in your web.config file.
See this answer for more information.
Upvotes: 0
Reputation: 6517
There is a setting to control whether the DEBUG constant is defined for each project based on the different deployment modes. See this answer to verify that the constant is being defined for 'release mode' by making sure the Define DEBUG constant
checkbox is checked.
If the box isn't checked, then your debug code is being removed by the preprocessor before compiling your site and no code will execute, even if you include the ELSE as the other answer suggested.
If that doesn't work, then another possibility is be that the machine you're running your release code on could have its machine.config
with the deployment element:
<deployment retail="true" />
This element overrides the web.config
setting for your application and sets the debug flag to false for all .NET applications on the machine.
So if possible, check that. Although I think the first option I gave you is much more likely.
Upvotes: 3
Reputation: 71
first of all you have to make sure that you step into this "if" and use try\catch.
#if (!DEBUG)
MessageBox.Show("I'm in");
try{
checkLicense();}
catch{MessageBox.Show("ERROR IN checkLicense");}
#endif
and than take a version out and run it. If you are in the "if", you will know it and if you have an exception, you will know it also.
You can try also
#if DEBUG
....
#else
.....
Upvotes: 0