无法在我的uwp应用中将对象存储在应用数据中

时间:2016-12-14 15:21:10

标签: c# .net wpf uwp

我正在尝试将对象存储在uwp app的appdata中。我从谷歌获得了一些代码,它正在为一个对象工作。我再次尝试保存另一个对象,但无法存储。得到这样的错误

  

DataContractAttribute属性,并标记要使用DataMemberAttribute属性序列化的所有成员。或者,您可以确保类型是公共的并且具有无参数构造函数 - 然后将序列化该类型的所有公共成员,并且不需要任何属性。*"

对象是:

public class CustomerAppSettingsResponse
{
    public List<ProductDiscountReason> productDiscountReasons { get; set; }
    public List<OutletDetail> outletDetails { get; set; }
    public List<TaxDetail> taxDetails { get; set; }
    public SettingsResponse settingsResponse { get; set; }
    public ResponseHeader responseHeader { get; set; }
    public List<ProductReturnReason> productReturnReasons { get; set; }
}

我用来存储数据的代码是:

private async Task<bool> SaveAppSettings(CustomerAppSettingsResponse objCustomerSettings)
{
    //AppSettings
    try
    {
        StorageFile AppsettingRes = await ApplicationData.Current.LocalFolder.CreateFileAsync(AppSettings, CreationCollisionOption.ReplaceExisting);
        using (Stream writeappstream = await AppsettingRes.OpenStreamForWriteAsync())
        {
            DataContractSerializer objappserializer = new DataContractSerializer(typeof(CustomerAppSettingsResponse));
            objappserializer.WriteObject(writeappstream, objCustomerSettings);
            await writeappstream.FlushAsync();
            writeappstream.Dispose();
        }
        return true;
    }
    catch (Exception e)
    {
        throw new Exception("Unable to save dtaa");
        return false;
    }
}

如何克服这一点。

0 个答案:

没有答案