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 6373327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:20:59+00:00 2026-05-25T01:20:59+00:00

I found a simple bug in VB.NET that can be easily reproduced: Dim pDate

  • 0

I found a simple bug in VB.NET that can be easily reproduced:

Dim pDate As Date?
Dim pString As String = ""

' works fine as expected
pDate = If(False, "", Nothing) 

' expected: pDate will be set to Nothing. 
' BUG: Conversion from string "" to type 'Date' is not valid.
pDate = If(False, pString, Nothing) 

'These both fail with the same error
pDate = pString
Dim pDate2 As Date? = "" 

Question: Is this a bug? Or is there something wrong with me or my PC?
If this is a bug, is there a bug report of this (I cant seem to find it)?

Lessons learned:

  1. this is not a bug
  2. nullable date accepts object nothing
  3. nullable date rejects string nothing

pDate = Nothing ' ok. nullable date accepts object nothing
pString = Nothing
pDate = pString ' error. nullable date rejects string nothing
  • 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-25T01:21:00+00:00Added an answer on May 25, 2026 at 1:21 am

    The bug is in your first use of If(), not the second. Contrary to your comment, the result there is not “expected”. That call should fail, because “” cannot convert to a date and the ternary operator is typesafe at all levels whether or not the expression is used.

    I suspect it succeeds because of a compiler optimization: since everything is all literals, the condition is optimized away. It’s harder to make the optimization the second time, because the pString variable might be changed by another thread the compiler doesn’t know about yet.

    Someone who’s handier with IL can probably confirm this.

    The real surprise for me is that this is not caught until runtime. I would expect the compiler to notice the type mismatch and complain at that level, rather than waiting until execution. Your VB Option settings may have something to do with that.

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

Sidebar

Related Questions

I am using a UI component from J2ME Polish. I found a simple bug
I have a very simple MVC site that is returning a 404 not found
Is there a simple way, without .NET? I've found some libraries but none for
Update: A sample project reproducing this bug can be found here at Microsoft Connect
Yesterday I discovered an odd bug in rather simple code that basically gets text
I have a simple .NET dll built with VS2010 C# that exposes 2 static
I've found plenty of simple, cheap solutions for recording composite video sources to my
I found an odd problem when I run a simple csh script on Solaris.
Hopefully a simple question although one I have found impossible to answer myself using
Simple question, but I haven't found a good explanation on google. When using Set

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.