By default, C # does not check for integer overflows, but VB.NET does.
You get the same exception in C # if you, for example. wrap your code in a checked block:
checked { uint value = 1161; byte data = (byte)value; }
In the properties of the VB.NET project, enable Configuration Properties => Optimizations => Remove Integer Overflow Checks, and your VB.NET code will work just like your C # code.
Integer overflow checks are then disabled for the entire project, but this is usually not a problem.
sloth
source share