views:

64

answers:

1

I get a Catastrophic Failure error when I try to create an image from a base64 encoded string sent in an XML file. I have the back-end guy who says it works but he uses WPF and Silverlight is different.

The code:

    void TagCloudImageCompleted(object sender, WebApiTagCloud.TagCloudImageCompletedEventArgs e)
    {
        String cloudImageResult = e.Result;
        //MessageBox.Show(cloudImageResult);

        XDocument cloudImageXML = XDocument.Parse(cloudImageResult);
        String bmpString = cloudImageXML.Element("TagCloudImage").Element("BitMapImage").Value;

        byte[] imageBytes = System.Convert.FromBase64String(bmpString);
        MemoryStream ms = new MemoryStream(imageBytes);
        BitmapImage im = new BitmapImage();
        im.SetSource(ms);
        LocationImage.Source = im;
        ms.Close();
    }

Since his version is working I have tried to verify that the data that I am getting is correct. But I haven't been able to verify with him yet that we are getting similar data.

The error on the line im.SetSource(ms);

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

+1  A: 

The code looks fine. However a key difference BitmapImage has with its WPF cousin is that it only supports JPEG and PNG. Check that one of these formats is being used.

AnthonyWJones