0

I'm trying to store and retrieve data without one application use , means it should refresh instantly on the other list when i redirect , but i'm facing some problem with the saving. would be nice if you could help me out. is the structure alright?

Serialization Exception Type 'System.Collections.Generic.List`1[[Med.sMedication, Med, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' with data contract name 'ArrayOfsMedication:http://schemas.datacontract.org/2004/07/MedReminder_v1' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

Class File

public class sMedication
{

    public string Name { get; set; }
    public string Remarks { get; set; }
    public string Dosage { get; set; }
    public string Duration { get; set; }
    public DateTime StartDate { get; set; }

    List<string> medicationItem = new List<string> { "", "", "", "", "" };

    public void addtoList()
    {

    }

    public object save(object bigobject)
    {
        List<Object> Obj = new List<Object>();
        Obj.Add(bigobject);

        var settings = IsolatedStorageSettings.ApplicationSettings;
        settings.Add("Obj", Obj);

        settings.Save();
        return true;
    }


}

Adding code

   private void Submit_Clicked(object sender, RoutedEventArgs e)
    {
        sMedication med = new sMedication();
        med.Name = txtName.Text;
        med.Dosage = txtDosage.Text;
        med.Duration = txtDuration.Text;
        med.StartDate = startDate.Value.Value;

        List<sMedication> medicationItem = new List<sMedication> { new sMedication { Name = med.Name, Dosage = med.Dosage } };

        //{ Name, Remarks, Dosage, Duration, Convert.ToString(StartDate) };

        med.save(medicationItem);
        NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
    }
4

1 回答 1

1

ApplicationSettings使用DataContractSerializer. 您可以自己使用它来测试对象的序列化。或者,您可以自己处理序列化(和反序列化)并将字符串存储在ApplicationSettings.

您的代码也比它需要的复杂得多。您正在尝试保存单个sMedication实例,但将其包装在 a 中List<sMedication>(即使只有其中一个),然后将其List<object>再次包装在 a 中,即使它只是一个对象。

于 2012-06-08T12:19:32.933 回答