robidd
robidd

Reputation: 53

Windows Phone 8 ImageSource cannot be serialized Error while sharing image

i am trying to share an image. I got a picture object and am getting the path from it. When I'm calling the ShareMediaTask it throw following error:

System.Windows.Media.ImageSource cannot be serialized.

I am still able to share the image, but the app crashes when returning from sharing.

Here is my code:

        PictureModel picture = Singleton.Instance.BearPicture.Model.Images.Where(PictureModel => PictureModel.Bmp.UriSource == (Image_View.Source as BitmapImage).UriSource).FirstOrDefault();


        var task = new ShareMediaTask();


        task.FilePath = picture.Picture.GetPath();

        task.Show();

My PictureModel looks like this:

 public class PictureModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    private string _uri;
    public string Uri
    {
        get { return _uri; }
        set
        {
            if (value != _uri)
            {
                _uri = value;
                NotifyPropertyChanged("Uri");
            }
        }
    }

    private string _relativePath;
    public string RelativePath
    {
        get { return _relativePath; }
        set
        {
            if (_relativePath != value)
            {
                _relativePath = value;
                NotifyPropertyChanged("RelativePath");
            }
        }
    }

    private BitmapImage _bmp;
    public BitmapImage Bmp
    {
        get { return _bmp; }
        set
        {
            if (value != _bmp)
            {
                _bmp = value;
                NotifyPropertyChanged("Bmp");
            }
        }
    }

    private Picture _picture;
    public Picture Picture
    {
        get { return _picture; }
        set
        {
            if (value != _picture)
            {
                _picture = value;
                NotifyPropertyChanged("Picture");
            }
        }
    }

    private void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

    }

}

Where does this error come from? I am only getting the Source of my image object but i am not doing anything else with it. My picture is also saved in the media library like this:

  myFileStream = myStore.OpenFile(fileName, FileMode.Open, FileAccess.Read);
            MediaLibrary library = new MediaLibrary();
            Picture pic = library.SavePicture(fileName, myFileStream);

On Appstart im searching through my savedpicture folder, to get the picture object, which is then saved in my PictureModel.

Any help is appreciated. Thanks in advance. robidd

Upvotes: 0

Views: 170

Answers (1)

jbarrameda
jbarrameda

Reputation: 1997

This may help: Crashes Back (WriteableBitmap cannot be serialized) windows phone 8. See the comment from KooKiz.

"Same symptoms, same cause. You've stored at some point an ImageSource in the phone state (probably PhoneApplicationService.Current.State or IsolatedStorageSettings.ApplicationSettings). You have to find where!"

Apparently we can cause this error indirectly. I'm having a similar problem and I found that answer and also your own question.

Hope it helps. Cheers.

Upvotes: 1

Related Questions