Click here to Skip to main content
15,894,546 members

How to fix: "OverflowException occurred Arithmetic operation resulted in an overflow"

Revision 2
My C# (asp) code is :

C#
int real_buffer_size=0;
				// allocate a dump memory space in order to retrieve nb of connexion
				int BufferSize = 100*CMIB_TCPEXROW.size_ex+4;//NumEntries*CMIB_TCPEXROW.size_ex+4
				IntPtr lpTable = Marshal.AllocHGlobal(BufferSize);
				
				}
				//get the number of entries in the table
Error Line==>	Int32 NumEntries= (int)Marshal.ReadIntPtr(lpTable);
				real_buffer_size=NumEntries*CMIB_TCPEXROW.size_ex+4;

				// check if memory was enougth (needed buffer size: NumEntries*MIB_UDPEXROW.size_ex +4 (for dwNumEntries))
				if (BufferSize<real_buffer_size)
				{
					// free the buffer
					Marshal.FreeHGlobal(lpTable);
	                
					// get the needed buffer size: NumEntries*MIB_TCPEXROW.size_ex +4 (for dwNumEntries)
					BufferSize = real_buffer_size;
					// Allocate memory
					lpTable = Marshal.AllocHGlobal(BufferSize);


when I run my C# code (ASP) it stop with error :
Quote:
OverflowException occurred
Arithmetic operation resulted in an overflow.


in line:
C#
Int32 NumEntries= (int)Marshal.ReadIntPtr(lpTable);


I know what the Error mean, but I do not know how to resolve it! which changes should I make to fix this error? (for example, which parameter should I change?)

Your Help will be Appreciated,
Posted 16-Jan-13 4:43am by keshtkar2.
Tags: ,