VB:
If (CULng(val) And &HFFFF000000000000UL) = &HFFFF000000000000UL
C#:
if (((ulong)val & 0xFFFF000000000000) == 0xFFFF000000000000)
My guess is that those don't produce identical IL. I don't know VB.NET syntax, but is there a way you can actually do a direct cast, like in C#? Using CULng(...) may be an optimized VB specific call that results in IL that's different from what'd be generated if you do a direct cast (assuming VB syntax supports that).