summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/Deserializer.cs
diff options
context:
space:
mode:
authordgeller-OUHSC <dgeller@ouhsc.edu>2017-10-03 10:23:32 (GMT)
committerKangho Hur <kangho.hur@samsung.com>2017-10-23 04:33:58 (GMT)
commit7accccfc353bda9088d4e9f1be780cc6624d5eca (patch)
treecc33c791b9f2f12957e1697cb3b9e69660365ffc /Xamarin.Forms.Platform.Android/Deserializer.cs
parent4d436f71bc9dece7abce4501747eae4292b676bf (diff)
downloadxamarin-forms-7accccfc353bda9088d4e9f1be780cc6624d5eca.zip
xamarin-forms-7accccfc353bda9088d4e9f1be780cc6624d5eca.tar.gz
xamarin-forms-7accccfc353bda9088d4e9f1be780cc6624d5eca.tar.bz2
[Core, Android] Fix to address the elusive 'Sharing violation on path PropertyStore.forms.tmp' (#1075)
* use a semaphor for actual saving piece make reading serialized propertystore readonly to help with collisions. * change over to async Task and await OnStateChanged() method to try and mitigate what might be the race condition causing the ' Sharing violation on path PropertyStore.forms.tmp' error * update Semaphore name * remove private specifier per the style guide * Update docs and add warning suppression for broken mono warning * ... and adding the warning suppression to Release mode, as well. * -add try...finally block so we can guarantee that the semaphore is released if there's an exception while saving the properties. -remove the legacy code that the semaphore replaces * Update docs * Attempting to fix docs * Trying again to get docs to pass
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Deserializer.cs')
-rw-r--r--Xamarin.Forms.Platform.Android/Deserializer.cs28
1 files changed, 17 insertions, 11 deletions
diff --git a/Xamarin.Forms.Platform.Android/Deserializer.cs b/Xamarin.Forms.Platform.Android/Deserializer.cs
index c85aaa7..ccce9cd 100644
--- a/Xamarin.Forms.Platform.Android/Deserializer.cs
+++ b/Xamarin.Forms.Platform.Android/Deserializer.cs
@@ -20,22 +20,28 @@ namespace Xamarin.Forms.Platform.Android
return Task.Run(() =>
{
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
- using (IsolatedStorageFileStream stream = store.OpenFile(PropertyStoreFile, System.IO.FileMode.OpenOrCreate))
- using (XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader(stream, XmlDictionaryReaderQuotas.Max))
{
- if (stream.Length == 0)
+ if (!store.FileExists(PropertyStoreFile))
return null;
- try
+ using (IsolatedStorageFileStream stream = store.OpenFile(PropertyStoreFile, System.IO.FileMode.Open, System.IO.FileAccess.Read))
+ using (XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader(stream, XmlDictionaryReaderQuotas.Max))
{
- var dcs = new DataContractSerializer(typeof(Dictionary<string, object>));
- return (IDictionary<string, object>)dcs.ReadObject(reader);
- }
- catch (Exception e)
- {
- Debug.WriteLine("Could not deserialize properties: " + e.Message);
- Log.Warning("Xamarin.Forms PropertyStore", $"Exception while reading Application properties: {e}");
+ if (stream.Length == 0)
+ return null;
+
+ try
+ {
+ var dcs = new DataContractSerializer(typeof(Dictionary<string, object>));
+ return (IDictionary<string, object>)dcs.ReadObject(reader);
+ }
+ catch (Exception e)
+ {
+ Debug.WriteLine("Could not deserialize properties: " + e.Message);
+ Log.Warning("Xamarin.Forms PropertyStore", $"Exception while reading Application properties: {e}");
+ }
}
+
}
return null;