Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6863255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:45:37+00:00 2026-05-27T02:45:37+00:00

When I use preprocessor directives like 1 #if(DEBUG) 2 // 1 3 // 2

  • 0

When I use preprocessor directives like

1 #if(DEBUG)
2 // 1
3 // 2
4 #else
5 // 1
6 // 2
7 #endif
8
9 logger.Debug("Log exception, etc."); 

it causes that at runtime the line numbers in the log (eg. stack trace) are incorrect – in the above example line 9 would become 4 because the rest would be parsed by the preprocessor.

It makes log analysis quite difficult.

Is there a way to solve this issue without creating methods with ConditionalAttribute?

I’m aware of Debugger.IsAttached (and I’m using this solution now) but I would prefer to run code based on the build mode (debug/release) not on whether the debugger is attached.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:45:38+00:00Added an answer on May 27, 2026 at 2:45 am

    I checked again in a completely separate project and as Ross Patterson suggests, the exception trace is correct.

    Unfortunately I already refactored my (large) project with Debugger.IsAttached and the problem went away so I (groundlessly as it turns out) suspected that preprocessor directives were the issue. Maybe the .pdb were not in sync with the binaries.

    Since I’m unable to reproduce the issue now I consider it solved. It’s good to know that this scenario is supported. Thanks Ross Patterson!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When working in Objective-C, when is it appropriate to use preprocessor directives like #ifdef
Are there any preprocessor symbols which allow something like #if CLR_AT_LEAST_3.5 // use ReaderWriterLockSlim
How to use preprocessor directives in BlackBerry JDE plugin for eclipse?
I would like to add some C# debug only code that only runs if
I'm trying to use preprocessor tricks to declare a magic variable. Something like this:
To support multiple platforms in C/C++, one would use the preprocessor to enable conditional
Is there a way to (ab)use the C preprocessor to emulate namespaces in C
I am using gfortran to compile FORTRAN 77 and would like to have DEBUG
I use Blackberry java plug-in for eclipse to write code. I have preprocessor statements
Edit: I know that method 1 is essentially invalid and will probably use method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.