When I add the type BitmapImage to my class for my Windows 8 application (below), I get the:
Cannot serialize member vehicleImage' of type 'Windows.UI.Xaml.Media.Imaging.BitmapImage', see inner exception for more details.
Inner Exception Details:
System.Runtime.InteropServices.WindowsRuntime.RuntimeClass is inaccessible due to its protection level. Only public types can be processed.
Code:
public BitmapImage vehicleImage
{
get
{
return m_vehicleImage;
}
set
{
Uri _baseUri = new Uri("ms-appx:///");
BitmapImage imageBitmap = new BitmapImage(new Uri(_baseUri, ImagePath));
m_vehicleImage = imageBitmap;
OnPropertyChanged("vehicleImage");
}
}
private async void SetImage()
{
var file = await Windows.Storage.KnownFolders.PicturesLibrary.GetFileAsync(ImagePath);
var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
var img = new BitmapImage();
img.SetSource(fileStream);
vehicleImage = img;
}
I’m serializing the object into XML. When I remove this bit of code everything works. I’d like to have the ability to have an image that the user selects from their computer (which is why I’m trying to use the BitmapImage type).
Any help is appreciated.
Use the System.Xml.Serialization namespace to access [XMLIgnore()] for these sort of properties.
You should want to store the string of where the image is, correct? Then you serialize the string, and [XMLIgnore()] the BitMapImage.
This allows the BitMap Image to still be accessed while serialization can occur.