Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未处理错误或异常_C#_Wcf_Windows Phone 7 - Fatal编程技术网

C# 未处理错误或异常

C# 未处理错误或异常,c#,wcf,windows-phone-7,C#,Wcf,Windows Phone 7,我指的是将图像从sql server检索到Windows phone,在该行上运行时,出现了未处理的错误 public class ImageConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { by

我指的是将图像从sql server检索到Windows phone,在该行上运行时,出现了未处理的错误

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; 
        }
    }
我发现另一个类似的帖子也有同样的错误。
但是不理解编码。有人知道如何解决错误吗?

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

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

这正是例外所说的
buffer
为空。但当我在编码中添加if(value!=null&&value为byte[])时。它向我显示错误并非所有代码路径都返回值..我已经尝试过了。该值为空..我认为可能是因为prob位于转换图像的部分。我用这个[将图像插入sql server。你能帮我看一下编码吗。我仍在努力理解这两种编码。。