0

I have a c# .net core project that is using preprocessor directives ( #if DEBUG) to enable unsafe SSL Connections during debugging. Now when I release-build the whole project and open the generated dll with dotPeek I still find the code surrounded by the '#if DEBUG' in there. I would have thought that this code is removed during the build. I also checked that in the BuildSettings from VS the "define DEBUG" is unchecked for the Release-Build-Configuration. Is my idea of how this works incorrect ? Where in the .dll would I find the definition of 'DEBUG' at all - at the top of the file or somewhere else ?

#if DEBUG
        DisableSecureSSLConnections();
#endif

Release Build Configuration

lb0
  • 23
  • 4
  • _"...I still find the code surrounded by the '#if DEBUG' in there..."_ - evidence? –  Jul 09 '21 at 09:15
  • A quick [test](https://sharplab.io/#v2:EYLgtghglgdgNAFxFANnAJiA1AHwAIBMADALABQ5AxOgKYBmsNABACICiAQgKoDiB5hAIzkBBJnkEB2JgG9yTBQrwBmcYIBs4gCxMAstBgAKCUQDaAXSYQATgHMAzgEo5ZRW4VUodVp179XihIAnIYARACeNPahjgDcVDQo9jTygYIhoTAA9jHxZJQ0MOheIgGKAL7klWVMQA===) shows that it actually works as intended. Depending on the `define`, the code will be omitted. – devsmn Jul 09 '21 at 09:19
  • dotPeek seeks out the *actual source code*, if it's available. It's not showing you the post-compile state. – Damien_The_Unbeliever Jul 09 '21 at 09:19
  • 1
    "*I still find the code surrounded by the '#if DEBUG' in there*" -- IL has no way to represent `#if`: there's no possible way for a disassembler to look at a dll and reconstruct an `#if`. So dotPeek is getting this from somewhere else. Most likely, it's found a .pdb file next to the DLL, and the .pdb has a path to the source code in it, so dotPeek has helpfully gone and found your *actual* source code and is displaying it to you. You should see other clues, such as source code which looks identical to your actual code, complete with comments and meaningful local variable names – canton7 Jul 09 '21 at 09:20
  • @canton7 thanks a lot - that was the actual problem. – lb0 Jul 09 '21 at 09:23

1 Answers1

1

As @canton7 mentioned in the comment section. The actual problem was the .pdb file was available for the disassembler. This caused dotPeek to show the actual source

lb0
  • 23
  • 4