Silverlight LocalSettings (IsolatedStorageSettings) 是否有 16k 的大小限制

发布于 2024-10-01 19:47:06 字数 434 浏览 4 评论 0原文

我正在尝试将整个视图模型保存到独立存储设置中。它非常大,因为它包含许多其他虚拟机。

当我尝试读取该值时,它会抛出“IsolatedStorageFileStream 上不允许操作”错误。这看起来像是转移注意力,因为我没有使用文件,而是使用isolatedStorageSettings类。

我检查了本地应用程序数据目录下的 __LocalSettings 文件,它似乎被截断为 16k(XML 元素名称的一半)。我怀疑它有 16k 的限制,因此在下次加载时,IsolatedStorage 类将其视为无效文件并抛出异常(然后将其清空回空文件)。

我想确认一下使用IsolatedStorageSettings 时您的所有设置是否有16k 的大小限制?

解决这个问题的一些方法是将其序列化为文件并重新水化它,而不是使用“设置”或根本不使用此方法(存储较少的信息)。任何人有更好的想法请告诉我?

I am trying to save my whole viewmodel into the IsolatedStorage Settings. It is quite large as it contains many other VMs.

When I try and read the value it throws a "Operation not permitted on IsolatedStorageFileStream" error. This seems like a red-herring as I am not using files, I am using the IsolatedStorageSettings class.

I checked out the __LocalSettings file under my local app data directory and it appears to be truncated at 16k (halfway through an XML element name). I suspect it has a 16k limit and therefore on the next load the IsolatedStorage class sees it as an invalid file and throws a fit (it then blanks it back down to an empty file).

I would just like to confirm if there is a size limit of 16k on all your settings when using IsolatedStorageSettings?

Some ways around it is to serialize it as a file and rehydrate it instead of using Settings or to not use this approach at all (store less info). In anyone has a better idea please let me know?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一城柳絮吹成雪 2024-10-08 19:47:06

IsolatedStorageFile。 IncreaseQuotaTo 是您的朋友。

另请查看 上的各种方法IsolatedStorageFile 类。

请参阅此处的示例 (请参阅“如何修改配额的示例?”部分)和此处

更新

另一方面,也许可以尝试通过设置外部文件的地址来增加设置文件的大小,而不是将它们嵌入到设置本身中,例如,如果您有一个大的 xml 文件,只需将设置设置为其地址并处理设置文件的事件(我假设它是 ApplicationSettingsBase)。

IsolatedStorageFile.IncreaseQuotaTo is your friend.

Also review the various methods on the IsolatedStorageFile class.

See examples here (see "Sample on how to modify the quota?" section) and here.

Update

In the other hand, maybe try to increase the size of the setting file by setting addresses to external files instead of embedding them in the setting itself, for example, if you have a big xml file, just set the setting to its address and handle the event of the settings file (I assume it's a subclass of ApplicationSettingsBase).

一花一树开 2024-10-08 19:47:06

好吧,经过更多的调查和胡思乱想,16k 的限制似乎是一个转移注意力的事情。它可能相关,但实际问题是序列化问题。

关于复杂类型到isolatedStorageSettings的序列化,这里似乎有两个问题。第一个是上面提到的,其中 _LocalSettings 类在 XML 元素的中间被截断为 16k。这会导致“IsolatedStorageFileStream 上不允许操作”异常。第二个是较小的复杂类型 - 在检查 _LocalSettings 的内容后,它似乎会写入它,但下次加载应用程序时,第一个 Settings.Save 会擦除所有现有设置(即,它不会加载现有的设置)并重新保存)。这使得 _LocalSettings 再次重置为空白(即,您的所有设置都不会保留)。

问题是我的一种基本类型(顺便说一下 MVVM Light ViewModelBase - 阅读更多关于this here)没有公共无参数构造函数,因此不可序列化(对此没有警告,它只是表现出上面的奇怪行为)。

你必须退出程序才能发生这种情况 - 当你在这样的写入后读取设置时,它工作正常 - 我怀疑 Silverlight 在你完全退出后在幕后做更多的事情。如果有人可以证实这一点吗?

一旦我使基类可序列化,它就会再次起作用。

Ok, after a lot more investigation and hair-pulling the 16k limit seems to be a red-herring. It may be relevant but the actual problem is a serialization issue.

There seems to be 2 issues here regarding the serialization of complex types to IsolatedStorageSettings. The first one is the one mentioned above where the _LocalSettings class is truncated at 16k halfway through an XML element. This causes the "Operation not permitted on IsolatedStorageFileStream" exception. The second is on a smaller complex type - after examining the contents of _LocalSettings it seems to write to it but then on the NEXT time you load up the app the first Settings.Save wipes all existing settings (ie. it does not load the existing ones and resave them). This makes the _LocalSettings reset to blank again (ie. ALL your settings are not persisted).

The problem was that one of my base types (incidentally the MVVM Light ViewModelBase - read more about this here) does not have a public paramaterless constructor and is therefore not serializable (there was no warning on this, it just exhibited the strange behaviours above).

You have to exit the program to have this happen - when you read the setting after a write like this it works fine - I suspect Silverlight is doing more behind the scenes after you exit completely. If anyone can confirm this??

As soon as I made the base class serializable then it worked again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文