gpt4 book ai didi

c# - 您能解释 .NET 运行时中的这种奇怪的崩溃吗?

转载 作者:太空狗 更新时间:2023-10-29 23:11:49 26 4
gpt4 key购买 nike

我的 C# 应用程序在抛出未处理的异常时向我发送堆栈跟踪,我现在正在查看一个我不理解的异常。

看起来这不可能是我的错,但通常是当我认为我随后被证明是错误的时候。 8-) 这是堆栈跟踪:

mscorlib caused an exception (ArgumentOutOfRangeException): startIndex cannot be larger than length of string.
Parameter name: startIndex
System.String::InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) + 6c
System.String::Substring(Int32 startIndex) + 0
System.IO.Directory::InternalGetFileDirectoryNames(String path, String userPathOriginal, String searchPattern, Boolean includeFiles, Boolean includeDirs, SearchOption searchOption) + 149
System.IO.Directory::GetFiles(String path, String searchPattern, SearchOption searchOption) + 1c
System.IO.Directory::GetFiles(String path) + 0
EntrianSourceSearch.Index::zz18ez() + 19b
EntrianSourceSearch.Index::zz18dz() + a

所以我的代码(最后混淆的函数名称)调用 System.IO.Directory.GetFiles(path),它因字符串索引问题而崩溃。

遗憾的是,我不知道传入的 path 的值,但无论如何,System.IO.Directory::GetFiles< 肯定是不可能的 那样崩溃?尽我所能,我无法为重现崩溃的 GetFiles 提出任何参数。

我真的是在查看 .NET 运行时中的错误,还是有什么东西可以合法地导致此异常? (如果在我调用 GetFiles 时目录正在更改,我可以理解会出现问题,但我不希望在这种情况下出现字符串索引异常。)

编辑:感谢大家的想法!到目前为止最有可能的理论是其中有一个带有狡猾的非 BMP Unicode 字符的路径名,但我仍然无法破解它。使用 Reflector 查看 GetFiles 中的代码,我认为它可以中断的唯一方法是 GetDirectoryName() 返回一个的路径它的输入,即使它的输入已经完全归一化。离奇。我试过用非 BMP 字符制作路径名(我从来没有一个名为 {MUSICAL SYMBOLG CLEF} before 8-) 但我还是不能让它坏掉。

我所做的是围绕失败的代码添加额外的日志记录(并确保我的日志记录适用于非 BMP 字符!)。如果再次发生这种情况,我会提供更多信息。

最佳答案

您可以尝试使用 .NET Reflector 查看 System.IO.Path.GetFiles() 的代码.快速看一下,它显然只调用 String.Substring() 来从路径的末尾拆分一些东西,并将其添加回方法的末尾附近。它检查 Path.DirectorySeparatorChar(反斜杠,'\')和 Path.AltDirectorySeparatorChar(斜杠,'/') 来确定子串的索引和长度。

我的猜测是无效或 unicode 文件或文件夹名称混淆了该方法。

关于c# - 您能解释 .NET 运行时中的这种奇怪的崩溃吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1324806/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com