Error ArgumentNullException was unhandled when retrieve image to window phone

hueikar

New member
Jun 7, 2012
3
0
0
Visit site
I am referring this Display Images from Database in Windows Phone 7 (WP7) using WCF service to retrieve image from sql server to window phone and had error ArgumentNullException was unhandled when run it at the that higlighted row.

public class ImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
byte[] buffer = value as byte[];
**Stream memStream = new MemoryStream(buffer);**
WriteableBitmap wbimg = PictureDecoder.DecodeJpeg(memStream);
return wbimg;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}

I had found another similar post had same error with me. System.ArgumentException was unhandled Message=The parameter is incorrect. - App Hub ForumsBut don't understand the coding..Anyone know how to solve the error? Or any other reference for me to retrieve image??
 
Last edited:

thed

New member
Jan 6, 2011
992
3
0
Visit site
The exception name is pretty self-explanatory - it means that the argument is null. So in this case, the variable "buffer" is null.

It's hard to say why without more information. What type is the "value" parameter? In the example it looks like value is already a byte array. Why are you using the buffer variable?
 

hueikar

New member
Jun 7, 2012
3
0
0
Visit site
Actually i not really understand the coding. just want to test the example 1st. I am using this Inserting and Retrieving images from SQL Server Database using C# | Redmond Pie to insert image into Sql server from web-based system. But want to retrieve image into window phone from Sql server according this link
Display Images from Database in Windows Phone 7 (WP7) using WCF service.I think the problem is at the convert image to byte or reverse..But both example show the image is datatype image..
 

dotnetnelson

New member
Jun 12, 2012
13
0
0
Visit site
The problem is likely that value is not of type byte[].

In C# when you use the "as" operator (for example in "value as byte[]") it tells the runtime:
Try to do a cast, if the cast fails set the variable to null.

So you getting an ArgumentNullException in the constructor of MemoryStream (which takes in the aforementioned null reference) is indicative of a bad cast.

In short, your types are incompatible. To test this theory, do an explicit cast "buffer = (byte[])value" which will throw an InvalidCastException if the types indeed don't match.
 

Members online

No members online now.

Forum statistics

Threads
323,183
Messages
2,243,404
Members
428,036
Latest member
Tallgeeselll05