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

  • Home
  • SEARCH
  • 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 392411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:09:23+00:00 2026-05-12T16:09:23+00:00

Why doesn’t #IF Not DEBUG work the way I’d expect in VB.NET? #If DEBUG

  • 0

Why doesn’t #IF Not DEBUG work the way I’d expect in VB.NET?

#If DEBUG Then
   Console.WriteLine("Debug")
#End If

#If Not DEBUG Then
   Console.WriteLine("Not Debug")
#End If

#If DEBUG = False Then
   Console.WriteLine("Not Debug")
#End If
' Outputs: Debug, Not Debug

But, a manually set const does:

#Const D = True
#If D Then
   Console.WriteLine("D")
#End If

#If Not D Then
   Console.WriteLine("Not D")
#End If
' Outputs: D

And, of course, C# has the expected behavior as well:

#if DEBUG
    Console.WriteLine("Debug");
#endif

#if !DEBUG
    Console.WriteLine("Not Debug");
#endif
// Outputs: Debug
  • 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-12T16:09:23+00:00Added an answer on May 12, 2026 at 4:09 pm

    Turns out, it’s not all of VB.NET that’s broken – just the CodeDomProvider (which both ASP.NET and Snippet Compiler use).

    Given a simple source file:

    Imports System
    Public Module Module1
        Sub Main()
           #If DEBUG Then
              Console.WriteLine("Debug!")
           #End If
    
           #If Not DEBUG Then
              Console.WriteLine("Not Debug!")
           #End If
        End Sub
    End Module
    

    Compiling with vbc.exe version 9.0.30729.1 (.NET FX 3.5):

    > vbc.exe default.vb /out:out.exe
    > out.exe
      Not Debug!
    

    That makes sense…I didn’t define DEBUG, so it shows “Not Debug!”.

    > vbc.exe default.vb /out:out.exe /debug:full
    > out.exe
      Not Debug!
    

    And, using CodeDomProvider:

    Using p = CodeDomProvider.CreateProvider("VisualBasic")
       Dim params As New CompilerParameters() With { _
          .GenerateExecutable = True, _
          .OutputAssembly = "out.exe" _
       }
       p.CompileAssemblyFromFile(params, "Default.vb")
    End Using
    
    > out.exe
    Not Debug!
    

    Okay, again – that makes sense. I didn’t define DEBUG, so it shows “Not Debug”. But, what if I include debug symbols?

    Using p = CodeDomProvider.CreateProvider("VisualBasic")
       Dim params As New CompilerParameters() With { _
          .IncludeDebugInformation = True, _
          .GenerateExecutable = True, _
          .OutputAssembly = "C:\Users\brackett\Desktop\out.exe" _
       }
       p.CompileAssemblyFromFile(params, "Default.vb")
    End Using
    
    > out.exe
    Debug!
    Not Debug!
    

    Hmm…I didn’t define DEBUG, but maybe it defined it for me? But if it did, it must have defined it as “1” – because I can’t get that behavior with any other value. ASP.NET, using the CodeDomProvider, must define it the same way.

    Looks like the CodeDomProvider is tripping over VB.NET’s stupid psuedo-logical operators.

    Moral of the story? #If Not is not a good idea for VB.NET.


    And now that source is available, I can verify that it does actually set it equal to 1 as I expected:

    if (options.IncludeDebugInformation) {
          sb.Append("/D:DEBUG=1 ");
          sb.Append("/debug+ ");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 192k
  • Answers 193k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You shouldn't put the test for malloc() in an assert():… May 12, 2026 at 6:28 pm
  • Editorial Team
    Editorial Team added an answer even if you don't stop, any change to the web.config… May 12, 2026 at 6:28 pm
  • Editorial Team
    Editorial Team added an answer I would code this like def current_account @account ||= current_subdomain.blank?… May 12, 2026 at 6:28 pm

Related Questions

Why doesn't this Google Chart API URL render both data sets on this XY
Why doesn't this work (when parameter is set to 1) : SELECT * FROM
Why doesn't the designer work if you inherit from an own written genericform? Suppose
Why doesn't the following work? (apply and (list #t #t #f)) While the following
Why doesn't Java include support for unsigned integers? It seems to me to be

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.