- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
从这篇博文看来,我应该能够将 DateTime
存储为 ApplicationData.LocalSettings
值,但我在下面得到了这一行的异常.
ApplicationData.Current.LocalSettings.Values["LastTokenRefresh"] = DateTime.UtcNow;
异常(exception):
Data of this type is not supported.
Error trying to serialize the value to be written to the application data store
我错过了什么?
我目前正在将 DateTime
转换为字符串以使其工作。
最佳答案
我认为是该博客的链接重定向问题导致您对支持的数据类型 DateTime
产生误解。可以引用官方文档:Types of app data ,本文档中的 DateTime
会将您链接到 DateTime structure :
JavaScript: This type appears as the Date object.
.NET: When programming with .NET, this type is hidden, and developers should use the System.DateTimeOffset structure.
C++: Similar to FILETIME but with important differences.
也就是说,这里支持的日期类型是System.DateTimeOffset Structure , 不是 System.DateTime Structure .因此,您可以像这样修改您的代码:
ApplicationData.Current.LocalSettings.Values["LastTokenRefresh"] = DateTimeOffset.UtcNow;
或者您可以继续使用您的 ToString()
方法来保存它,但是当您检索此字符串类型值时,您可能需要重建字符串以便在您的代码中使用它。
关于c# - ApplicationData.LocalSettings 中的日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40710715/
我正在使用 MS EnterpriseLibrary.Logging,它运行良好,但日志文件位于程序可执行目录中。 我如何才能将我的日志文件放在单个用户的 applicationData 文件夹中?
我正在尝试获取当前登录用户的应用程序数据文件夹的路径。 我正在使用 Environment.GetFolderPath(Environment.SpecialFolder.ApplicationDat
从这篇博文看来,我应该能够将 DateTime 存储为 ApplicationData.LocalSettings 值,但我在下面得到了这一行的异常. ApplicationData.Current.
我有一个空白的 UWP 应用程序,我在 ApplicationData 中写了一些设置,当我增加我的包版本时,我的 applicationData 版本没有改变。另一个问题是,当我使用 SetVers
以下链接解释了允许在设备之间漫游的最大数据大小,并且一旦超过 100KB 限制,所有漫游功能将停止。 https://msdn.microsoft.com/en-us/library/windows/
在我的应用程序中,我将所有数据存储在 ApplicationData 中,以便它可以在 Activity 之间轻松共享。我的理解是,这些数据应该在应用程序从最初的 onCreate 到最后的 onDe
我正在尝试关注 UWP with Desktop Extension – Part 2 UWP 和 WinForms 桌面桥调用进程和传递参数。此示例控制台 Program.cs代码包括参数字符串:
我有一个奇怪的问题:我的 .NET 4.0 WPF 应用程序正在将数据保存到 ApplicationData 文件夹。 Environment.GetFolderPath(Environment.S
事实证明,当您尝试存储枚举值时,WinRT 保存设置的能力会引发异常。 MSDN 在页面上说 "Accessing app data with the Windows Runtime"只有"Runti
总结:几个不同的用户将在特定机器上使用我的应用程序。我希望应用程序将其数据存储在这台机器上的单个公共(public)文件中,而不管哪个用户正在运行该应用程序。 为了实现我想要的,我想知道这个问题是否相
我有一个带有表单和文本字段的 Tab GUI 扩展。我想将表单字段的值保存到 ApplicatioData。我正在考虑调用 Anguilla 方法的“更新”按钮。 有安圭拉方法可以做到这一点吗?我在安
在我的系统上,%AppData%导致 ApplicationData这是 C:\Users\\AppData\Roaming 但是还有C:\Users\\AppData\Local 还有一些困惑D:\
有谁知道,我必须在 Unity 项目目录结构中放置一个文件(sqlite 文件),以便在 apk 编译和安装后,该文件仍然存储在 Android 端的 persistedDataPath 中? 提前致
我有一个与 WCF 服务捆绑在一起的桌面应用程序。两者都是使用 .NET 4.7.2 构建的。应用程序和服务彼此共享一个安装目录,并且它们都使用 NLog 4.5.8 进行日志记录。它们各自使用 NL
我在我的一位客户的计算机上遇到了一个非常奇怪的行为,我找不到任何线索来解释为什么会这样:当应用程序调用 Environment.GetFolderPath(Environment.SpecialFol
我的 C++ 代码,属于 Media Foundation Transform 的一部分倾向于能够在 Windows Store App (Metro) 中运行 我修改了 C++ GrayscaleT
我正在尝试将文件存储到 Windows Phone 8.1 应用程序的应用程序存储中,但它总是失败并出现系统。UnauthorizedAccessException。 异常发生在下面一行(之前没有相关
我需要将一个文件安装到 Environment.SpecialFolder.ApplicationData 文件夹中,该文件夹在 XP 和 Vista 之间有所不同。是否有内置方法可以引用 WiX 中
我有一个 asp.net mvc3 应用程序。现在我想将用户数据保存在 C:\Users{AppPoolUserAccount}\AppData\Roaming\MyProgramm... 在第一次调
在我的应用程序运行期间,我将 txt 文件中的一些数据保存到以下位置:Windows.Storage.ApplicationData.Current.LocalFolder在 Windows 10 P
我是一名优秀的程序员,十分优秀!