Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#ASP.NET
My C# (asp) code is :
 
 
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:
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
Edited 16-Jan-13 4:45am
v2
Comments
Nick Fisher (Consultant) at 16-Jan-13 10:46am
   
Which line does it fail on? A bit more info will help to get the best response.
Mathlab at 16-Jan-13 11:56am
   
1. Breakpoint 2. Watch your locals window 3. Increase the size of variable overflowing 4. Change the type to var of the variable overflowing and do not cast it to int 5. Start at 1. if it fails
Richard MacCutchan at 16-Jan-13 12:56pm
   
I suspect the actual error occurs on the following line where you are multiplying two values together. Add some debug code to see what the two values are.
jkirkerx at 16-Jan-13 18:44pm
   
case from int to int32, I've had trouble with that in the past

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This looks like horrible code to run in a web page. What is it doing ? You are doing a cast, what does ReadIntPtr return ? I suggest stuffing your return value in to the right type, without casting. Then you will know for sure if the call itself is failing, or the cast. Are you sure that lpTable has a good value in it ? Have you debugged this ?
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 696
1 OriginalGriff 468
2 Tadit Dash 390
3 sanket saxena 337
4 Peter Leow 228
0 Sergey Alexandrovich Kryukov 11,890
1 OriginalGriff 7,335
2 Peter Leow 5,003
3 Abhinav S 3,943
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web02 | 2.8.140421.2 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid