當C#應用程序拋出一個未處理的異常時,它會向我發送一個堆棧跟蹤,現在我正在看一個我不明白的異常。你可以在.NET運行時解釋這種奇怪的崩潰嗎?
看起來好像這不可能是我的錯,但通常當我認爲我後來被證明是錯誤的。 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字符製作路徑名(我在8-之前從來沒有一個名爲{MUSICAL SYMBOL G CLEF}的目錄),但我仍然無法讓它斷開。
我所做的是在失敗的代碼中添加額外的日誌記錄(並確保我的日誌記錄可以與非BMP字符一起工作!)。如果再次發生,我會獲得更多信息。
也許它試圖查看具有損壞的文件名的目錄? – 2009-08-24 21:16:32
什麼是System.IO.Directory::GetFiles(String path)+ 0中的參數值? – Yakeen 2009-08-24 21:16:38
您的應用程序是否包含任何本機代碼? – 2009-08-24 21:17:17