Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# IsolatedStorageFileStream导致断言失败_C#_Windows 7_Isolatedstoragefile - Fatal编程技术网

C# IsolatedStorageFileStream导致断言失败

C# IsolatedStorageFileStream导致断言失败,c#,windows-7,isolatedstoragefile,C#,Windows 7,Isolatedstoragefile,我决定对临时文件使用独立存储: using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForDomain()) { using (IsolatedStorageFileStream userStream = new IsolatedStorageFileStream("UserSettings.set", FileMode.Create, isoStore)) { } } 我从这台计

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

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

    }
}
我从这台计算机上运行的示例中获取了这段代码。只有这段代码的最小项目也成功运行

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

MyApp.exe-断言失败

表达式:[mscorlib递归资源查找错误]

描述:在mscorlib中查找资源时无限重复。 这可能是mscorlib中的错误,也可能是某些扩展性中的错误 程序集解析事件或CultureInfo名称等点

资源名称:Serurity_Generic

在这条消息中,我可以看到相当大的堆栈跟踪(它从调用
IsolatedStorageFileStream
constructor开始):

此外,我无法捕获此代码中的异常

似乎在
System.Environment.resourceheloper.GetResourceStringCode()
中发生了错误

可能的原因是什么?我找不到关于这个话题的任何东西


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

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


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

在我的情况下,当我的代码试图在
IsolatedStorage
中创建一个新的文件时,在一些机器上发生了这种情况。正如在的注释中正确提到的,只有当机器设置了非英语活动区域设置时,才会发生这种情况。以下代码修复了我的案例中的问题:

var currentCulture = Thread.CurrentThread.CurrentCulture;
var currentUiCulture = Thread.CurrentThread.CurrentUICulture;

Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

var traceFileStream = new IsolatedStorageFileStream("system_log.txt", FileMode.OpenOrCreate, FileAccess.Write);

Thread.CurrentThread.CurrentCulture = currentCulture;
Thread.CurrentThread.CurrentUICulture = currentUiCulture;

它看起来确实像库中的一个bug:据我所知,在尝试解析程序集时,它对引用的程序集调用
GetName
,从而导致加载引用的程序集。所以它返回到AssemblyResolve,然后再次调用GetName,然后返回到AssemblyResolve,依此类推。你是对的。我不得不将当前线程的区域性更改为“en-US”来修复它。