错误ArgumentNullException未处理

时间:2012-06-07 18:38:31

标签: c# wcf windows-phone-7

我指的是这个http://www.dotnetcurry.com/ShowArticle.aspx?ID=585来检索从sql server到window phone的图像,并且当在那个被忽略的行上运行它时,ArgumentNullException未被处理。

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; 
        }
    }

我发现另一个类似的帖子和我有同样的错误。 http://forums.create.msdn.com/forums/p/74224/452127.aspx 但是不明白编码..任何人都知道如何解决错误?

1 个答案:

答案 0 :(得分:0)

看起来为空或不是字节数组。

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
    WriteableBitmap wbimg = null;

    if (value != null && value is byte[]) {
        byte[] buffer = value as byte[];
        Stream memStream = new MemoryStream(buffer);
        wbimg = PictureDecoder.DecodeJpeg(memStream);
    }

    return wbimg; 
}