In my universal Windows application, I store user data by converting its objects to xml files through XmlSerializer.
The application was to compile, build and work fine until then (without any changes in the code) the assembly for release began to give me this error: System.InvalidOperationException: failed to generate a temporary class (result = 1) .
If I create or run a debugging application, it works flawlessly, but when I release (with an active .NET chain active) I get an error message.
I already gave permission to the C: \ Windows \ Temp folder to everyone. Even my mother has access to her, but the error remains.
If this is really a read / write problem on XmlSerializer, I am wondering if there is a way to change the serializer temporary folder in a UWP project .
Here is the code I used to serialize the objects:
public static async Task<T> ReadObjectFromXmlFileAsync<T>(string filename) { // this reads XML content from a file ("filename") and returns an object from the XML T objectFromXml = default(T); var serializer = new XmlSerializer(typeof(T)); StorageFolder folder = ApplicationData.Current.LocalFolder; StorageFile file = await folder.GetFileAsync(filename).AsTask().ConfigureAwait(false); Stream stream = await file.OpenStreamForReadAsync().ConfigureAwait(false); objectFromXml = (T)serializer.Deserialize(stream); stream.Dispose(); return objectFromXml; } public static async Task SaveObjectToXml<T>(T objectToSave, string filename) { // stores an object in XML format in file called 'filename' var serializer = new XmlSerializer(typeof(T)); StorageFolder folder = ApplicationData.Current.LocalFolder; StorageFile file = await folder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting).AsTask().ConfigureAwait(false); Stream stream = await file.OpenStreamForWriteAsync().ConfigureAwait(false); using (stream) { serializer.Serialize(stream, objectToSave); } } //This uses a subfolder public static async Task<T> ReadObjectFromXmlFileAsync<T>(string filename) { // this reads XML content from a file ("filename") and returns an object from the XML T objectFromXml = default(T); var serializer = new XmlSerializer(typeof(T)); StorageFolder folder = ApplicationData.Current.LocalFolder; StorageFolder subFolder = await folder.GetFolderAsync("Notes").AsTask().ConfigureAwait(false); StorageFile file = await subFolder.GetFileAsync(filename).AsTask().ConfigureAwait(false); Stream stream = await file.OpenStreamForReadAsync().ConfigureAwait(false); objectFromXml = (T)serializer.Deserialize(stream); stream.Dispose(); return objectFromXml; }
What am I missing? Can anyone help?
source share