I'm getting this error
System.OverflowException: Arithmetic operation resulted in an overflow.
when i ran my application on Windows Server 2008 R2 Standard compiled in .Net 2.0 or greater (.Net 4.0). From what i know, C# should ignore Arithmetic overflow if it is compiled without /checked parameter. In my app there are many places where overflow can happened, so i need to ignore it.
I traced one example:
using System;
namespace ArithmeticOverflow
{
class Program
{
static void Main( string[] args )
{
GetTypeID( typeof( Program ) );
}
public static int GetTypeID( Type type )
{
return type.GetHashCode() ^ type.FullName.GetHashCode() ^ type.TypeHandle.Value.ToInt32();
}
}
}
Compiled with .net 2.0:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe /out:test.exe Program.cs
When i run this program on my desktop computer, everything go fine. But when i run it on server, it crash. I cannot find the problem.
If i compile it with .net 1.1:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc.exe /out:test.exe Program.cs
It is alright on desktop PC and on server too. So where is the problem ? Please help.
UPDATE
Solved by using /platform:anycpu32bitpreferred
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\csc.exe /unsafe /platform:anycpu32bitpreferred /out:test.exe Program.cs