Windows 7 64bit - Arithmetic operation resulted in an overflow

Mar 4, 2010 at 1:22 PM


i get an error:

rapi.CopyFileToDevice(input + @"\export\art.txt", @"\art.txt", true);

I have downloaded the lates version of NETCF.


Mar 4, 2010 at 1:31 PM

Seems that you are not using the last source code from the repository.

Mar 11, 2010 at 7:51 AM


i have downloaded the latest source code but the problem is still there...

What can i do ?


Mar 11, 2010 at 3:23 PM

Ok problem solved, Robert was right: download and compile the latest Source code and USE IT IN YOUR PROJECT! :)

Jun 15, 2010 at 2:53 AM

I have had this problem too on moving to 64-bit Windows 7, and the latest source code did not solve the problem.


However, I tracked it down to the use of IntPtr (handle). Some of the handles returned were outside the range of a signed 32-bit int.



private const short INVALID_HANDLE_VALUE = -1;   


private IntPtr INVALID_HANDLE_VALUE = (IntPtr)(-1);


and removing any (int) casts in comparisons with INVALID_HANDLE_VALUE solved the problem for me.

Jul 29, 2010 at 1:53 PM

Very Good my friend!


It's works fine!

Jan 3, 2011 at 5:55 PM

Does anyone related to the project know when this fix will be implemented on the official source?

Thanks oneillpetert for the code change information.




Jan 3, 2011 at 6:54 PM

It's already fixed and implemented since over a year.

Feb 23, 2012 at 8:34 PM

Actually, I just downloaded the latest code and this has not been fixed. I had to do what oneillpetert recommended to get to work.

Feb 23, 2012 at 8:52 PM

Just look at the changeset: and you'll see it was fixed on Wed Sep 23 2009 at 10:56 PM.

May 17, 2012 at 10:46 PM

Downloaded today (2012-05-17) and get the same error. Download my patch (or whoops just noticed urmstores already submitted a patch for the same issue so you can also try his/hers) to get around the issue. Error occurs when running on 64 bit systems.

Jul 12, 2012 at 10:34 PM

You don't need to apply a patch. Just download the latest source code from the repository. There have been other improvements and bugfixes too.

Jul 24, 2012 at 11:29 AM

I have tried all the fixes that has been outlined within this forum and I am still receiving the error:

System.OverflowException: Arithmetic operation resulted in an overflow. as System.IntPtr.op(Explicit(IntPtr value) at OpenNETCF.Desktop.Communication.RAPI.SetDeviceFileTime(String FileName, RAPIFileTime DesoredTime, DateTime NewTime) at OpenNETCF.Desktop.Communication.RAPI.CopyFileTODevice(String LocalFileNmae, String REmotrFileName, Boolean Overwrite)

Does anyone know what I should do?

Sep 10, 2014 at 11:40 AM
I also have the same problem with "Arithmetic operation resulted in an overflow", when running an application on win7 64bit version

problems with these:

Do anyone have a solution?
Sep 10, 2014 at 1:54 PM
I got it working, seems that I had compiled the dll with "Any CPU" in visual studio 2008.
After compiling the code again with "64 bit cpu" it workes just fine.