Click here to Skip to main content
Rate this: bad
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);
				// check if memory was enougth (needed buffer size: NumEntries*MIB_UDPEXROW.size_ex +4 (for dwNumEntries))
				if (BufferSize<real_buffer_size)
					// free the buffer
					// 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 :
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 5:43am
Edited 16-Jan-13 5:45am
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
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 ?

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

  Print Answers RSS
0 George Jonsson 175
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100