Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 884395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:44:36+00:00 2026-05-15T12:44:36+00:00

can someone confirm that microsoft changed path length related behaviour of some classe from

  • 0

can someone confirm that microsoft changed path length related behaviour of some classe from System.IO in .NET 4.0? For example the code below runs fine on .NET 3.5 but on 4.0 throws a PathTooLongException for me.

const string prefix = "C:\\";
const string suffix = ".txt";

var sb = new StringBuilder();
sb.Append(prefix);
for (var i = 0; i < 260 - prefix.Length - suffix.Length - 1; i++)
{
    sb.Append("a");
}
sb.Append(suffix);

var info = new FileInfo(sb.ToString());

Also, a call to File.Create(sb.ToString()) throws an IOException on .NET 3.5 but an PathTooLongException on .NET 4.0. There might more differences.

Are these changes documented somewhere?

Thank You!

[EDIT]

I followed Hans Passant’s advice and filed a report on connect.microsoft.com. You can find it over here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:44:37+00:00Added an answer on May 15, 2026 at 12:44 pm

    Editing my answer, the original one was incorrect. Yes, the Path.NormalizePath() method went through some major changes in .NET 4.0. I managed to get this debugged with the Reference Source and found a comment in the source code that explains its behavior:

        // The max total path is 260, and the max individual component length is 255. 
        // For example, D:\<256 char file name> isn't legal, even though it's under 260 chars. 
        internal static readonly int MaxPath = 260;
        private static readonly int MaxDirectoryLength = 255; 
        ...
            if (newBuffer.Length - 1 - lastDirectorySeparatorPos > MaxDirectoryLength)
            { 
                throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); 
            }
    

    That’s the exception that is tripped by your code. It looks screwy because the code appears to check the directory name length which is obviously not close to 255 chars in your code. However, the comment explains why your path is rejected, the file name part of the path is 259-3 = 256 characters. One too many.

    I was not previously aware of this restriction and am a bit doubtful that all versions of Windows have this restriction. All I’ve seen documented that there’s indeed a maximum length of the directory name (path minus filename). There are other comments in the code that suggest that there is an off-by-one bug in Windows 2000, that might have something to do with it.

    Anyhoo, you can see this for yourself by changing

            const string prefix = "C:\\a\\";
    

    And now a path string of 259 chars is accepted. In other words, this behavior should only ever byte if the path name refers to the drive root folder. Not a place where you ever should store files.

    Given the comment in the source code, this change was quite intentional and should be regarded as a feature, not a bug. Nevertheless, I posted a comment to the feedback article you started. I’m still not buying it completely…


    Update: okay I’m sold on it. I tried creating such a file using C++ on Win7 and it failed. Files in the root directory indeed cannot have path names longer than 258 chars. The restriction appears to be induced by a component of the path (subdirectory name, file name) not allowed to be longer than 255 chars. The .NET 4.0 behavior is entirely correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone confirm that the below code definitely removes items from the BlockingCollection foreach
Can someone confirm that for a 32bit system: Is there any disadvantage in using
Can someone confirm that Python 2.6 ftplib does NOT support Unicode file names? Or
Can someone please confirm that the following is a bug with PHP 5.2.13: (thank
Can someone else confirm that autocomplete HTML tags is not working in Visual Studio
Please can someone confirm that '000' access permissions for admin files is secure? I
I was wondering if someone can confirm that App.Config file is cached by CLR
I hope that someone can help me with an issue related to binding a
Can someone confirm that firefox (3.6) automatically runs the javascript function named 'onload' without
Can someone confirm that -checkResourceIsReachableAndReturnError: method of NSURL is working as expected. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.