I received this strange warning “opcode ‘conv.ovf.i’ – overflow will not throw exception” in a project that I’m working on. I was only able to find one other mention of this warning in a Google search ([url]http://groups.google.com/group/microsoft.public.dotnet.framework.microframework/browse_thread/thread/48f10d2344c080f7[/url]), but the user had no answer for it. The warning was pointing to the byte array declaration:
byte[] postData = new byte[contLen];
in the function:
protected byte[] ReceivePostData(HttpListenerRequest request)
{
long contLen = request.ContentLength64;
byte[] postData = new byte[contLen];
int dataRead = request.InputStream.Read(postData, 0, (int)contLen);
if (dataRead != 0)
{
return postData;
}
}
After looking at the code a little longer, I realized I was casting the long to an int for the
request.InputStream.Read()
function, I decided to try and cast it at the byte array declaration as well, so the declaration reads:
byte[] postData = new byte[(int)contLen];
.
This cast eliminated this warning.
I wanted to share this in case anyone else encountered this warning, as it is not immediately obvious what is causing this warning.