Visual Studio - PathTooLongException even when the path length is less than 260 characters
Asked Answered
F

4

7

I know that max path length allowed while creating a project is 260 characters and 248 characters for directory. But I'm getting this error even when my my path length is less than 200 characters.

My solution file resides in this folder C:\Users\username\Documents\Visual Studio 2010\Projects\Health12.Domain12.WardManagement => 88 characters When I try to add a new class library with name "Health12.Domain12.WardManagement.Service.Contract" to this solution, it gives me path too long exception.

C:\Users\username\Documents\Visual Studio 2010\Projects\Health12.Domain12.WardManagement\Health12.Domain12.WardManagement.Service.Contract => 138 characters

C:\Users\username\Documents\Visual Studio 2010\Projects\Health12.Domain12.WardManagement\Health12.Domain12.WardManagement.Service.Contract\Health12.Domain12.WardManagement.Service.Contract.csproj => 195 characters

None of the possible files or folders crosses the 260 character limit.

If i change the project name from "Health12.Domain12.WardManagement.Service.Contract" to "Health12.Domain12.WardManagement.Service.Con", it works fine. Any idea why visual studio won't allow to create project even when it is not crossing max allowed length limit.

Floozy answered 23/7, 2013 at 10:12 Comment(1)
Windows 10 added the capability to use paths > 260 characters. You can do that via the registry or the group policies as described here: howtogeek.com/266621/…Convey
Y
9

The length of the path in Visual Studio is computed as follow:

  1. Path to solution: C:\Users\username\Documents\Visual Studio 2010\Projects\Health12.Domain12.WardManagement\ = 89 chars
  2. 2 * Project name : Health12.Domain12.WardManagement.Service.Contract\ = 50 chars
  3. Reserved chars : Additionnal characters for the files in the project, the compiled files, temporary files, ... = 80 chars

In your case: 89 + 2*50 + 80 = 269

The limit is 259 ((Drive char):\(256-character path)) (see Naming Files, Paths, and Namespaces)

You have to remove 10 chars. Either you reduce the length of the path to the project by 10 chars or you remove 5 chars in the project name ("tract" for example works).

Yawning answered 23/7, 2013 at 11:47 Comment(3)
Thanks for great explanation. But I did not understand why it multiplies the project name length by 2. Any idea?Floozy
Because there are lot of temporary and output files that contains the project name. (For example: Path to Solution/Project name/obj/Release/Project name.FileListAbsolute.txt)Judaea
There is no such limit. I have much longer paths, for example created by GitHub Desktop which can handle them. So is there a solution for Nuget package manager?Halifax
R
8

This limit is part of the Windows Kernel and is hardly solvable. I found a workaround that ALLOW working with path with more than 260 chars.

Disclaimer: I've tried this trick only on Windows 8 x64 and Visual Studio 2013

So, to make it work I've just create a junction to the folder with the mklink command:

Assume this is the original path: d:\very\very\long\path\to\solution\folder, you can obtain a short link as d:\short_path_to_solution_folder just jaunching this command from a dos shell as administrator:

mklink /J d:\short_path_to_solution_folder d:\very\very\long\path\to\solution\folder

change source and destination path to meet you needs.

Best Regards! Stelvio

Rompish answered 4/3, 2015 at 9:26 Comment(2)
The OP writes that the 260 chars limit isn't reached, but maybe this could help out as well.Haslett
Thanks, good idea, but now the only problem is that now git is having the same issue, and this hides the ancestor git folder, you just can't win, no pun intendedUnconscious
D
7

You could try and change the set path value in regedit to value of 1 and see of that helps. It should be under Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem>LongPathsEnabled Good luck!

Devotional answered 8/4, 2020 at 2:25 Comment(3)
May I ask what error message did you get? Or what did not work? Where did you get something that say did not work?Devotional
Since this was in Feb the only error I can think of is the error in the title of this question.Monteria
hi sorry to hear it didn't solve it but "C:\Users\username\Documents\Visual Studio 2010\Projects\Health12.Domain12.WardManagement" is only the start - from there you get your scripts and bin/debug/blah/name.health12.Docmain12.WardManagement.dll etc. if you didn't change it in the Regedit then you should have this more often. else you are running a SPA page with node_modules that definitely will push that over. if you've solved this great for you. else Good luck! let us know when you find a solutionDevotional
G
0

Create a folder in DESKTOP and then create your project using visual studio on that folder. Once the .sln file is saved you can move the folder to your original directory, you can open the .sln file which runs successfully. It worked for me.

Govea answered 2/11, 2022 at 4:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.