• 00Days
  • 00Hours
  • 00Mins
  • 00Secs
Check out the best deals!
  1. hueikar's Avatar
    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 by hueikar; 06-07-2012 at 01:55 PM.
    06-07-2012 01:49 PM
  2. thed's Avatar
    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 likes this.
    06-07-2012 03:29 PM
  3. hueikar's Avatar
    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..
    06-08-2012 01:54 AM
  4. dotnetnelson's Avatar
    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.
    06-12-2012 08:24 PM

Tags for this Thread

LINK TO POST COPIED TO CLIPBOARD