Can you explain this weird crash in the .NET runtime?

My C # application sends me a stack trace when it throws an unhandled exception, and I look at it now when I don’t understand.

It seems that this may not be my mistake, but usually when I think that later I am mistaken. 8-) Here's the stack trace:

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

So my code (the names of the confusing functions at the end) is causing System.IO.Directory.GetFiles(path)that to crash with the row indexing problem.

Unfortunately, I do not know the value paththat was transmitted, but regardless of this, really shouldn't it be possible for the crash System.IO.Directory::GetFiles? Try so that I cannot come up with any argument GetFilesthat reproduces the failure.

.NET, -, ? ( , , , GetFiles, .)

: ! , Unicode, BMP, . GetFiles Reflector, , , , - GetDirectoryName() , , . Bizarre. BMP- ( {MUSICAL SYMBOL G CLEF} 8-), .

- ( , BMP!). , .

+5
9

System.IO.Path.GetFiles() .NET Reflector. , -, String.Substring(), - . Path.DirectorySeparatorChar ( , '\') Path.AltDirectorySeparatorChar ( , '/'), .

, unicode .

+2

... - 256 ? System.IO Framework.Net , , .

+1

.. , - .

, , ?

  • , , , .
  • , "un-obfuscated" ?
  • - Path, Path.Exist() Path.IsValid(), . , "/" "\" , , API , - - ? , .

, ! , , , .

+1

, , . : 1. 2. 3..Net-, , vs .Net-, .

, .

: , ++. - ?

, , , , . : http://support.microsoft.com/kb/943804/

+1

: " ChkDsk?"

+1

, - . . . .

?

0

, , GetFiles Visual ++, C:, , . .

0

, , UNC , . , 8.3, UNC-, Windows 2000 Windows XP. ( , .)

.

    String tempStr = Path.InternalCombine(fullPath, searchPattern);

    // If path ends in a trailing slash (\), append a * or we'll
    // get a "Cannot find the file specified" exception
    char lastChar = tempStr[tempStr.Length-1];
    if (lastChar == Path.DirectorySeparatorChar || lastChar == Path.AltDirectorySeparatorChar || lastChar == Path.VolumeSeparatorChar) 
        tempStr = tempStr + '*';

    fullPath = Path.GetDirectoryName(tempStr); 
    BCLDebug.Assert((fullPath != null),"fullpath can't be null!");

    String searchCriteria;
    bool trailingSlash = false;
    bool trailingSlashUserPath = false;

    lastChar = fullPath[fullPath.Length-1];
    trailingSlash = (lastChar == Path.DirectorySeparatorChar) || (lastChar == Path.AltDirectorySeparatorChar); 

    if (trailingSlash) {
        // Can happen if the path is C:\temp, in which case GetDirectoryName would return C:\ 
        searchCriteria = tempStr.Substring(fullPath.Length);
    }
    else
        searchCriteria = tempStr.Substring(fullPath.Length + 1); 
0

. , GetFiles. , - , ?

0

All Articles