How to Enable and Troubleshoot Long Path Support in Windows Server 2016 for Developers


2 views

Despite Microsoft's introduction of long path support (paths exceeding 260 characters) in Windows 10 and Server 2016, many developers still encounter the classic "path too long" errors during file operations. This happens even after modifying the registry settings as recommended in official documentation.

For true long path support, three conditions must be met simultaneously:

1. Windows 10 Anniversary Update (1607) or later / Windows Server 2016 or later
2. Application manifest declaring longPathAware
3. Enabled via Group Policy or Registry: 
   Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
   LongPathsEnabled (DWORD) = 1

Most developers miss one crucial aspect - the application manifest requirement. Even with system-level settings enabled, traditional Win32 applications won't automatically support long paths. Here's how to properly configure a .NET application:

<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
      <longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
    </windowsSettings>
  </application>
</assembly>

When dealing with existing files that exceed the limit, PowerShell provides useful alternatives:

# Using the \\?\ prefix for native API calls
Get-ChildItem -LiteralPath "\\?\C:\extremely\long\path\..." 

# Robocopy alternative
robocopy "source" "destination" /mir /xj

Create this test script to verify long path support:

using System;
using System.IO;

class Program {
    static void Main() {
        try {
            string longPath = @"C:\" + new string('a', 300);
            Directory.CreateDirectory(longPath);
            Console.WriteLine("Successfully created 300+ char path!");
        } catch (Exception ex) {
            Console.WriteLine($"Failed: {ex.Message}");
        }
    }
}

For enterprise environments, these additional registry tweaks might be necessary:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"LongPathsEnabled"=dword:00000001
"SymlinkLocalToLocalEvaluation"=dword:00000001
"MaximumComponentLength"=dword:00000100

For applications you can't modify, consider these solutions:

  • Use subst command to create virtual drives: subst X: C:\deep\path
  • Implement a file system filter driver
  • Use the Win32 API with \\?\ prefix directly

Despite Microsoft's introduction of long path support in Windows 10 (1607) and Server 2016 through the EnableWin32LongPaths registry setting, many administrators still encounter the infamous 260-character path limitation during file operations. This happens because the change requires both system-level configuration and application-level compatibility.

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"LongPathsEnabled"=dword:00000001

But this alone isn't sufficient. You must also:

  • Ensure all applications are manifest-enabled (more on this below)
  • Verify the Group Policy setting matches your registry change
  • Check for filesystem-level restrictions (especially on network shares)

Modern applications must include this declaration in their manifest:

<application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
        <longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
    </windowsSettings>
</application>

In my experience troubleshooting Server 2016 installations, these scenarios often cause issues:

// PowerShell test for long path support
$longPath = "C:\" + ("a" * 200) + "\" + ("b" * 50) + ".txt"
try {
    New-Item -Path $longPath -Force
    Write-Host "Long path creation successful"
} catch {
    Write-Host "Failed with error: $_"
}

When accessing files via UNC paths, remember that the server and client must both support long paths. The complete path including the server name (\\server\share\...\file) counts toward the limit.

For legacy applications that can't be modified, consider these workarounds:

  1. Use the \\?\ prefix for API calls (e.g., \\?\C:\very...\long\path)
  2. Create symbolic links to reduce path depth
  3. Use Robocopy with the /256 switch for file operations

This C# code verifies your configuration is actually working:

using System;
using System.IO;

class Program {
    static void Main() {
        string root = @"C:\Test";
        string path = root;
        
        for (int i = 0; i < 30; i++) {
            path += @"\" + new string('d', 10);
        }
        
        path += @"\testfile.txt";
        
        try {
            Directory.CreateDirectory(Path.GetDirectoryName(path));
            File.WriteAllText(path, "Test content");
            Console.WriteLine($"Successfully created: {path.Length} characters");
        } catch (Exception ex) {
            Console.WriteLine($"Failed: {ex.Message}");
        }
    }
}