frosty
frosty

Reputation: 5370

Exception with System.Drawing.Image

hey guys, i'm getting an exception on the following

inner exception: {"Value cannot be null.\r\nParameter name: String"}

Which reads like a simple error message, but none of the values (image, fileName) are null. How can i find out where this null String is?

RipHelper.UploadImage(image, fileName);

which calls

public static void UploadImage(System.Drawing.Image image, string fileName)
        {
// this line is never reached
         }

Here is the full error log

#

System.ArgumentNullException: Value cannot be null. Parameter name: String at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Int32.Parse(String s) at Helpers.RipHelper..cctor() in C:\Helpers\RipHelper.cs:line 23 --- End of inner exception stack trace --- at Helpers.RipHelper.UploadImage(HttpPostedFile uploadFile, String fileName) at Helpers.UploadHelper.UploadImage(HttpContext context) in C:\Helpers\UploadHelper.cs:line 79

Upvotes: 1

Views: 1381

Answers (5)

frosty
frosty

Reputation: 5370

Thanks guys. Lesson learnt 'Pay more attention to the error log'. Here the culprit

private static readonly int previewImageHeight = int.Parse(ConfigurationManager.AppSettings["PreviewImageHeight"]);

PreviewImageHeight was misspelt in the config.

Upvotes: 0

Coderer
Coderer

Reputation: 27304

The .cctor() makes it sound like maybe you have a problem in the constructor of your RipHelper class. Can you step through the code in debug mode and see what line is actually throwing the exception?

Upvotes: 1

Steven A. Lowe
Steven A. Lowe

Reputation: 61242

RipHelper line 23 is trying to convert a null string into an integer, and failing. This is probably in a constructor or static initializer. Do you have access to the RipHelper source code?

Upvotes: 1

James Curran
James Curran

Reputation: 103565

The error is occuring in the static constructor of the RipHelper class.

Upvotes: 1

to StackOverflow
to StackOverflow

Reputation: 124794

The exception is in the static constructor of the class Helpers.RipHelper, at line 23 of RipHelper.cs. This line is calling Int32.Parse, passing a null value.

Perhaps the static constructor is referencing a static field that has not yet been initialized. If you are having trouble debugging this, post the code of the class including the static constructor and any field initializers.

Upvotes: 3

Related Questions