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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:29:57+00:00 2026-05-22T17:29:57+00:00

Late At Work last night, we were trying to figure out why something was

  • 0

Late At Work last night, we were trying to figure out why something was failing. A validation check was failing when it shouldn’t have been.

We ended up adding a print statement to this code (disassembled from Reflector in order to check that the code was actually what we had written):

public static string Redacted(string name, DateTime lastModified)
{
    long ticks = lastModified.Ticks;
    if ((ticks != (ticks - (ticks % 10000L))) &&
            (lastModified != DateTime.MaxValue))
    {
        Log.Debug(string.Format("Last Modified Date = '{0}'. Ticks = '{1}'. TicksCalc = '{2}'",
            lastModified.ToString("dd/MM/yyyy hh:mm:ss.fff"),
            ticks, ticks - (ticks % 10000L)));

It printed (reformatted):

Last Modified Date = '22/03/2011 12:16:22.000'.
Ticks     = '634363497820000000'.
TicksCalc = '634363497820000000'            

But the condition is that “ticks” (which is equal to Ticks printed above) is not equal to “(ticks - (ticks % 10000))” (which is equal to TicksCalc)! 634363497820000000 != 634363497820000000?!

In order to determine what is going on here, we added another two statements:

long ticks = lastModified.Ticks;
/* Added following two lines: */
long num2 = ticks - (ticks % 10000L);
Log.Debug((ticks == num2).ToString());
/* */
if ((ticks != (ticks - (ticks % 10000L))) &&
        (lastModified != DateTime.MaxValue))
{
    Log.Debug(string.Format("Last Modified Date = '{0}'. Ticks = '{1}'. TicksCalc = '{2}'",
        lastModified.ToString("dd/MM/yyyy hh:mm:ss.fff"),
        ticks, ticks - (ticks % 10000L)));

As it should have, this one printed true (when testing with the same value), and didn’t write the second line.

Feeling a bit lost, we then removed the two lines again, recompiled, and reran. The original behaviour repeated itself.

This morning, I recorded a video.

The video first of all shows hitting a breakpoint in the method using the ‘broken’ code, then rebuilding and rerunning using the ‘working’ code. Note that even though the debugger displays that the if condition evaluates as to false, the body is still entered.

I’ve seen things like this happen before when observed by the debugger, due to the debugger forcing some things to be evaluated, but this happens whether or not the debugger is employed.

Furthermore, this only happens in Release mode (i.e. with JIT optimizations enabled).

Here are the disassembled methods for both versions: working, not working. I can’t really read assembly, so am posting them here in the hopes of elucidation.

I hope that the answer isn’t something obvious that I’ve overlooked completely…!

Edit: Here is the IL. I don’t think there’s anything wrong with it because it decompiles to the correct C#:

  • Not working
  • Working

Update:

Confirmed as a bug by Microsoft, to be fixed in the next release.

  • 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-22T17:29:58+00:00Added an answer on May 22, 2026 at 5:29 pm

    I experimented a bit with simplified code:
    http://nopaste.info/2c99a0e028_nl.html

    The most interesting variation is:

    static readonly long variableZero=0; 
    const long constZero=0; 
    
    public static void Broken2( long ticks2) 
     { 
         long ticks = ticks2+variableZero; 
         if (ticks != (ticks - (ticks % 10000L))) 
         { 
             string.Format("Last Modified Date = '{0}'. Ticks = '{1}'. TicksCalc = '{2}'", 
                 "n/A", 
                 ticks, ticks - (ticks % 10000L)).Dump(); 
         } 
     }
    

    If I replace variableZero with constantZero it works.


    So I’m pretty sure it is either a jitter or a compiler bug.

    I’ve filed a bugreport on MS Connect:
    https://connect.microsoft.com/VisualStudio/feedback/details/671105/jitter-or-c-compiler-bug#details


    Update: The strange behavior only occurs if no debugger is attached. i.e. when Jit optimization is enabled. So I’m pretty sure it’s a jitter bug.

    And for people without linq-pad there is now a plain C# console project: http://nopaste.info/00a0e37328_nl.html

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

Sidebar

Related Questions

Its late and I have been trying to work on a simple script to
As of late, my team and I have been hard at work turning our
It's late and I can't figure out what is wrong with my syntax. I
Well it's late so I assume I'm just exhausted but I've been trying to
Questions about renaming files in Git have been asked before, but I can't work
Maybe it's just late, but I cannot figure out why this isn't working. When
Gday All, I have been dabbling in some F# of late and I came
I've been working with the Dropbox API as of late, and have run into
I am trying to find out more about the work distribution between the processes
Of late, I have a tendency to validate my stored procedure action query arguments

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.