Anyone has any idea why this error is happening? The weird thing is that this page works in one server but not in another.

Parameter is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Parameter is not valid.

Source Error:

Line 37:
Line 38: Dim streamImage As MemoryStream = New MemoryStream(byteImage) Line 39: Dim bitmapImage As Bitmap = Bitmap.FromStream(streamImage) Line 40: Dim imageId As Integer Line 41: Dim opeSubNum As String = txtSubNum.Text & "" & txtMonth.Text & "" & txtYear.Text

Source File: E:\wwwroot\secure\scan.aspx Line: 39

Stack Trace:

[ArgumentException: Parameter is not valid.] System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData) +1157767 System.Drawing.Image.FromStream(Stream stream) +8 ASP.secure_scan_aspx.uploadScan(String type) in E:\wwwroot\secure\scan.aspx:39 ASP.secure_scan_aspx.btnUploadOther_Click(Object sender, EventArgs e) in E:\wwwroot\secure\scan.aspx:188 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

Image.FromStream throws an ArgumentException if you call it with null as an argument or if the given stream does not contain an image in a valid (and supported) format.

Since you set streamImage on the line above, it is probably safe to assume that it is not null. So the likely explanation is that the data in byteImage is badly formatted or corrupted.

But the weird thing is that if I open the page from the former server, it works without a problem. This page is a asp 2.0, the new server runs framework 4.0, do you think this has anything to do with the framework version?