#

UWP Fehler: Datum-Variable Error trying to serialize the value to be written tot he application data store
 
Wenn man versucht ein Datum in die Settings der UWP App zu speichern, dann kommt der Fehler
Fehlermeldung

Error trying to serialize the value to be written tot he application data store

 
Fehlerhafte Code-Zeile in C#

ApplicationData.Current.LocalSettings.Values["DateStart_TestPeriod"] =DateTime.Now;

 

 
 
Lösung:
Man muss beim Speichern und Rücklesen einer Datum Variable in die Settings und von den Settings eine Konvertierung in string() machen
Konvertierung in String

ApplicationData.Current.LocalSettings.Values["DateStart_TestPeriod"] = _Store_DateStart_TestPeriod.ToString();

 
Rück-Umwandlung beim Lesen

_Store_DateStart_TestPeriod = Convert.ToDateTime(ApplicationData.Current.LocalSettings.Values["DateStart_TestPeriod"]);

 
 

 
 
Neuer C# Code

//----< get Start_Testperiod >----
try
{
//< Get Setting >
var varDateStart_TestPeriod = ApplicationData.Current.LocalSettings.Values["DateStart_TestPeriod"];
//</ Get Setting >
 
if (varDateStart_TestPeriod is null)
{
//< init testperiod >
_Store_DateStart_TestPeriod = DateTime.Now;
//< Save Setting >
ApplicationData.Current.LocalSettings.Values["DateStart_TestPeriod"] = _Store_DateStart_TestPeriod.ToString();
//</ Save Setting >
//</ init testperiod >
}
else
{
//< convert setting >
_Store_DateStart_TestPeriod = Convert.ToDateTime(varDateStart_TestPeriod);
//</ convert setting >
}
}
catch (Exception ex)
{
//< error >
MessageDialog dialog = new MessageDialog( ex.Message , "Information");
await dialog.ShowAsync();
return false;
//</ error >
}
//----</ get Start_Testperiod >----

 
 
Falscher Code C#

//< Get Setting >
var varDateStart_TestPeriod = ApplicationData.Current.LocalSettings.Values["DateStart_TestPeriod"];
//</ Get Setting >
 
if (varDateStart_TestPeriod is null)
{
//< init testperiod >
_Store_DateStart_TestPeriod = DateTime.Now;
//< Save Setting >
ApplicationData.Current.LocalSettings.Values["DateStart_TestPeriod"] = _Store_DateStart_TestPeriod;
//</ Save Setting >
//</ init testperiod >
}

 
 
 
Mobile

.

0123movie.net