Arithmetic operation resulted in an overflow c#
<p>I am getting the following error when unlocking a file</p>
<blockquote>
<p>Arithmetic operation resulted in an overflow</p>
<p>System.IntPtr.ToInt32</p>
</blockquote>
<p>I suspect it is the following line to <code>pBuffer.ToInt32()</code> :</p>
<pre><code>IntPtr iPtr = new IntPtr(pBuffer.ToInt32() + (i * Marshal.SizeOf(fi3)));
</code></pre>
<p>I am unable to reproduce the error myself and the error is not displaying the correct line number. I am looking for a way to reproduce this or any feedback on the possible cause.  Thanks</p>
<pre><code>public void Close()
{
        const int MAX_PREFERRED_LENGTH = -1;
        int readEntries;
        int totalEntries;
        IntPtr pBuffer = IntPtr.Zero;
        FILE_INFO_3 fi3 = new FILE_INFO_3();
        int iStatus = NetFileEnum(this.HostName, this.HostPathToShare + this.FileNameFromShare, null, 3, ref pBuffer, MAX_PREFERRED_LENGTH, out readEntries, out totalEntries, pBuffer);
        if (iStatus == 0)
        {
            for (int i = 0; i &lt; readEntries; i++)
            {
                IntPtr iPtr = new IntPtr(pBuffer.ToInt32() + (i * Marshal.SizeOf(fi3)));
                fi3 = (FILE_INFO_3)Marshal.PtrToStructure(iPtr, typeof(FILE_INFO_3));
                NetFileClose(this.HostName, fi3.fi3_id);
            }
        }
        NetApiBufferFree(pBuffer);
}

[DllImport(&quot;netapi32.dll&quot;, SetLastError=true, CharSet = CharSet.Unicode)]
static extern int NetFileClose(
    string servername,
    int id);

[DllImport(&quot;Netapi32.dll&quot;, SetLastError=true)]
static extern int NetApiBufferFree(IntPtr Buffer);

[DllImport(&quot;netapi32.dll&quot;, SetLastError=true, CharSet=CharSet.Unicode)]
static extern int NetFileEnum(
     string servername,
     string basepath,
     string username,
     int level,
     ref IntPtr bufptr,
     int prefmaxlen,
     out int entriesread,
     out int totalentries,
     IntPtr resume_handle
);
</code></pre>
<p><strong>Update</strong></p>
<p>I added the win32 apis code.</p>
<p>The below answers look correct and the machine is 64 bit.  But I am unable to reproduce it on the dev server despite the dev environment being 64 bit.  Any ideas to reproduce the error?</p>