c# - isolatedStorageFileStream导致断言失败

标签 c# windows-7 isolatedstoragefile

我决定对临时文件使用独立存储:

using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForDomain())
{
    using (IsolatedStorageFileStream userStream = new IsolatedStorageFileStream("UserSettings.set", FileMode.Create, isoStore))
    {

    }
}

我从在这台计算机上运行的示例中获取了这段代码。仅使用此代码的最小项目也可以成功运行。

但是在我当前的项目中执行 IsolatedStorageFileStream 构造函数时,会出现以下消息:

MyApp.exe - Assert Failure

Expression: [mscorlib recursive resource lookup bug]

Desctiprion: Infinite recurion during resource lookup within mscorlib. This may be a bug in mscorlib, or potentially in certain extensibility points such as assembly resolve events or CultureInfo names.

Resource name: Serurity_Generic

在此消息中,我可以看到相当大的堆栈跟踪(它以调用 IsolatedStorageFileStream 构造函数开始):

enter image description here

而且我无法从这段代码中捕获异常。

看起来 System.Environment.ResourceHelper.GetResourceStringCode() 中发生了错误。

造成这种情况的可能原因是什么?我找不到有关此主题的任何内容。

删除 C:\Users\user\AppData\Local\IsolatedStorage 文件夹并不能解决问题(我确信只有我的文件夹)。

最佳答案

查看堆栈跟踪,基本问题来自 LongPathFile.GetLength。路径中可能存在一些无效字符,或者可能存在权限问题。如果没有确切的错误代码,很难判断。 然后,.NET 尝试加载与错误代码相关的错误消息,并在某个时刻进入 Costura.AssemblyLoader(这必须是您的代码或您正在引用的某些库)。看起来 AssemblyLoader 订阅了 AssemblyResolve 事件,并且在获取正确的程序集方面表现不佳,因为它实际上导致了无限递归。

简而言之:修复该程序集加载器,然后您将能够得到真正的错误。

关于c# - isolatedStorageFileStream导致断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48879548/

相关文章:

c# - 这个字符串有什么问题?

get - UWP:从 'get; & set;' 中的 FilePath 设置 image.source

c# - 删除 ListViewItem 集合中所有选定项目的最有效方法是什么?

c++ - EnumProcessModules 在 32 位 win7 上失败并出现错误 299

c++ - MySQL Workbench 无法启动

c - 如何以编程方式将应用程序固定在 Windows 7 的“开始”菜单上

c# - 您如何获得 IsolatedStorage 中所有文件的平面列表?

c# - DownloadString 跳过换行符

c#检查程序是否在启动时运行