Path Too Long Problem MAX_PATH = 260 Chars kernel32.dll

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • frankstuartbrowne
    New Member
    • Jul 2007
    • 4

    Path Too Long Problem MAX_PATH = 260 Chars kernel32.dll

    This is a continuation the following post:



    The code I'm looking at is here, in the Finding Files and Directories part:



    I've gotten the code to run, but it crashes on the following line:

    found = FindNextFile(fi ndHandle, out findData);

    It mostly fails when a long filename is passed into it, for example: thisisareallylo ngfilename.txt

    Where simple.txt works fine.

    Anyone know why this happens?

    Thanks
  • TRScheel
    Recognized Expert Contributor
    • Apr 2007
    • 638

    #2
    After reading that, it seems that FindFilesAndDir s assumes that the \\?\ switch is passed. If it isnt, it will run into the same roadblocks as the normal methods of finding files and directories.

    Are you passing in file names with '\\?\' prepended?
    Last edited by TRScheel; Jul 27 '07, 04:06 PM. Reason: Removed Quote

    Comment

    • frankstuartbrowne
      New Member
      • Jul 2007
      • 4

      #3
      Yes, I've changed their version around a little.

      public static List<string> FindFilesAndDir s(string dirName)
      {
      dirName = @"\\?\" + dirName;
      ...
      }

      btw, the error that I'm getting is "...Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack..."

      Does this help?

      Originally posted by TRScheel
      After reading that, it seems that FindFilesAndDir s assumes that the \\?\ switch is passed. If it isnt, it will run into the same roadblocks as the normal methods of finding files and directories.

      Are you passing in file names with '\\?\' prepended?

      Comment

      • TRScheel
        Recognized Expert Contributor
        • Apr 2007
        • 638

        #4
        Originally posted by frankstuartbrow ne
        Yes, I've changed their version around a little.

        public static List<string> FindFilesAndDir s(string dirName)
        {
        dirName = @"\\?\" + dirName;
        ...
        }

        btw, the error that I'm getting is "...Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack..."

        Does this help?
        The call to that function is recursive. You need to prepend that outside the function, not within. At least, thats my take on it. If you look within the if / else block of the do / while (found) loop, it calls itself. In that call to itself it has:

        [CODE=cpp]Path.Combine(di rName, currentFileName );[/CODE]

        if dirName has the '\\?\' within it, and is passed to the function, you prepend it again. I am not sure if that is cause for error or not though. A simple fix would be to instead at the beginning of the function write:


        [CODE=cpp]dirName = dirName.StartsW ith(@"\\?\") ? dirName : @"\\?\" + dirName;[/CODE]


        On an aside, please read up about CODE tags. They are used as such:

        {code=VALUE}... code within here ... {/code}

        Where { and } are replaced with [ and ] respectively. VALUE can be omitted and you can just have {code} (again, replace { } ) or VALUE can be:

        cpp
        vbnet
        html

        And many more that are not coming to mind at the moment. For C#, cpp is most appropriate

        Comment

        • frankstuartbrowne
          New Member
          • Jul 2007
          • 4

          #5
          I'd like to say that helped, but it doesn't seem to be the case. After further research I'm pretty sure the problem has something to do with kernel32.dll. I've noticed that the code *sometimes* works. I use the same starting directory each time, and sometimes it successfully navigates through it, and sometimes it breaks. Here is the error when it breaks:

          "FatalExecution EngineError was detected

          The runtime has encountered a fatal error. The address of the error was at 0x79e8a634, on thread 0x7e8. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack."

          One of the recommendations to solve this problem is to completely remove Visual Studio and reinstall a version with the latest updates. Other fixes I've heard of involve how my environment is setup (managed, native, etc.)

          I've also read that this error is going to be resolved with the next VS update..


          Originally posted by TRScheel
          The call to that function is recursive. You need to prepend that outside the function, not within. At least, thats my take on it. If you look within the if / else block of the do / while (found) loop, it calls itself. In that call to itself it has:

          [CODE=cpp]Path.Combine(di rName, currentFileName );[/CODE]

          if dirName has the '\\?\' within it, and is passed to the function, you prepend it again. I am not sure if that is cause for error or not though. A simple fix would be to instead at the beginning of the function write:


          [CODE=cpp]dirName = dirName.StartsW ith(@"\\?\") ? dirName : @"\\?\" + dirName;[/CODE]


          On an aside, please read up about CODE tags. They are used as such:

          {code=VALUE}... code within here ... {/code}

          Where { and } are replaced with [ and ] respectively. VALUE can be omitted and you can just have {code} (again, replace { } ) or VALUE can be:

          cpp
          vbnet
          html

          And many more that are not coming to mind at the moment. For C#, cpp is most appropriate

          Comment

          • Jane Fox
            New Member
            • Aug 2008
            • 2

            #6
            I was trying to figure out on how to use that unicode functions, spent lots of time on this and finally bought SDK to handle it at <link removed>
            Last edited by Curtis Rutland; Aug 27 '08, 01:27 PM. Reason: Removed Link

            Comment

            • Jane Fox
              New Member
              • Aug 2008
              • 2

              #7
              Originally posted by Jane Fox
              I was trying to figure out on how to use that unicode functions, spent lots of time on this and finally bought SDK to handle it at <link removed>
              <link removed again>
              Last edited by Curtis Rutland; Aug 28 '08, 01:29 PM. Reason: Removed Link

              Comment

              • Curtis Rutland
                Recognized Expert Specialist
                • Apr 2008
                • 3264

                #8
                Please don't reopen a thread from a year ago just to post a link to a product. I can see that this product is relevant to the thread, but it is still considered spamming.

                MODERATOR

                Comment

                • Adam Fisher
                  New Member
                  • Oct 2013
                  • 1

                  #9
                  You can try "Long Path Tool" program.

                  Comment

                  • Zeeshan123
                    New Member
                    • May 2014
                    • 1

                    #10
                    try using long path tool for this

                    Comment

                    Working...