Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

DirectoryNotFoundException: Could not find a part of the path 'D:\ncrunch\workspace\56184\132\...
damianh
#1 Posted : Monday, May 27, 2024 4:09:58 PM(UTC)
Rank: Member

Groups: Registered
Joined: 5/5/2014(UTC)
Posts: 25
Location: Netherlands

Thanks: 2 times
Was thanked: 5 time(s) in 5 post(s)
NCrunch V5.7.0.3

I'm getting this error when NCrunch is trying to build one of my test projects:

Quote:

The file 'D:\repos\company\repo\src\MyApp\tests\MyApp.Tests\Path\File.txt' could not be written to the workspace due to error:
System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\ncrunch\workspace\56184\132\src\MyApp\tests\MyApp.Tests\Path\File.txt'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
at nCrunch.Common.IO.FilePath.CopyTo(FilePath destinationPath, Boolean waitForLock)
at nCrunch.Core.ProjectItems.SnapshotComponentMember.WriteToFile(FilePath fileToWriteTo)
at nCrunch.Core.WorkspaceManagement.WorkspaceBuilder.(SnapshotComponentMember )

NCrunch: v8.0.300 of the Dotnet SDK is being used by the NCrunch client, but this server is using v, which is the closest matching version found installed. This may cause issues with the build system. Consider installing v8.0.300 of the Dotnet SDK on this machine.


The test project has some txt files that are copied to the build output directory (with appropriate csproj itemgroup). When I look into "D:\ncrunch\workspace\56184\", the directory "132" is not there. ("131" and other "previous" numbered directories, however, are). I've "anonymised" the path above however it is a long path, in case that might be an issue (I've enabled long paths in the OS).

I've tried the "Additional files to include" but that didn't make any difference. I keep coming back to the fact that "\132" doesn't exist is where the problem is. Note this number changes after I perform "Reload and rebuild selected component", but the result is still the same.

Any ideas how to resolve?

Edit: that last message "but this server is using v, " seems it has bugs.
Remco
#2 Posted : Tuesday, May 28, 2024 12:11:45 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,555

Thanks: 1030 times
Was thanked: 1385 time(s) in 1286 post(s)
Hi, thanks for sharing this issue.

I think the first thing we should try is moving your workspace closer to your disk root, in an effort to make sure this isn't a long path issue (recognising that you have long paths enabled, but I've found support for these to be hit-and-miss in various parts of the platform). Setting it to something like 'D:\WS' could be worth doing just to see if it gets rid of the error. If it does, you might be able to find something closer to the root that is a bit more descriptive.

Is this problem showing up on a grid node? If so, does it work for you locally?
damianh
#3 Posted : Thursday, May 30, 2024 8:28:47 AM(UTC)
Rank: Member

Groups: Registered
Joined: 5/5/2014(UTC)
Posts: 25
Location: Netherlands

Thanks: 2 times
Was thanked: 5 time(s) in 5 post(s)
I've set the workspace directory to D:\ws as suggested. The path is 244 characters (under the 260 to be consider 'long') and the exact same error still occurs.

I'm not using Grid Node here, just vanilla plugin (VS and Rider)

I'm a loss here...
Remco
#4 Posted : Thursday, May 30, 2024 10:05:45 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,555

Thanks: 1030 times
Was thanked: 1385 time(s) in 1286 post(s)
Ok, I'm hopeful we can rule out a path error. Could you submit a bug report after the problem has appeared? Perhaps the log file will shed some light on what's happening here.
1 user thanked Remco for this useful post.
nikize on 6/4/2026(UTC)
damianh
#5 Posted : Friday, May 31, 2024 9:25:23 AM(UTC)
Rank: Member

Groups: Registered
Joined: 5/5/2014(UTC)
Posts: 25
Location: Netherlands

Thanks: 2 times
Was thanked: 5 time(s) in 5 post(s)
Ok will do. I'll try to create a minimal repro. It'll take me a few days.
1 user thanked damianh for this useful post.
Remco on 5/31/2024(UTC)
nikize
#6 Posted : Wednesday, June 3, 2026 11:02:59 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/15/2025(UTC)
Posts: 7
Location: Sweden

Thanks: 7 times
Was thanked: 1 time(s) in 1 post(s)
Just got similar:

Code:

The file 'C:\dev\projpath\obj\Debug\netstandard2.0\projname.GlobalUsings.g.cs' could not be written to the workspace due to error: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\MyUser\AppData\Local\NCrunch\46876\35\projpartialpath\obj\Debug\netstandard2.0\projname.GlobalUsings.g.cs'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at nCrunch.Common.IO.FilePath.<>c__DisplayClass39_0.<WriteContent>b__0()
at nCrunch.Core.WorkspaceManagement.WorkspaceBuilder.writeMemberToDisk(SnapshotComponentMember member)


Error output does link
https://www.ncrunch.net/...ng_project-build-issues
But from the output it is not clear what is going on, after changing NCrunch Workspace setting this particular one was solved. But still has another:

Code:

NCrunch: If you are experiencing problems in getting this project to build, have a look at https://www.ncrunch.net/documentation/troubleshooting_project-build-issues
..\..\..\..\Program Files\dotnet\sdk\10.0.300\Roslyn\Microsoft.Managed.Core.targets (198, 5): Could not find a part of the path 'C:\dev\.NCrunchWs\101776\25\projpath\obj\Debug\netstandard2.0\projname.GeneratedMSBuildEditorConfig.editorconfig'.

This path is in total 263 chars, won't be able to cut that down, (other than potentially renaming the project, and that won't fly)

Suggestions:
* Include the `System.IO.DirectoryNotFoundException: Could not find a part of the path` as an example of to long path on the otherwise great page.
* Catch the exception and show info on how long the path is and what the max is.
If we could somehow even slim down the path to not get the error in the firstplace would be great, but I fully acknowledge the difficulties in doing so, in this case
Remco
#7 Posted : Wednesday, June 3, 2026 12:19:46 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,555

Thanks: 1030 times
Was thanked: 1385 time(s) in 1286 post(s)
Thanks for sharing this.

As you can probably guess, NCrunch has a long history when it comes to issues with long paths. After fighting to find ways of improving this for many years, I've come to the conclusion that there isn't a safe way to report this problem without an extremely high chance of misleading false positives.

Part of the problem is that handling for long paths is extremely inconsistent through the platform. What works perfectly fine in some situations will fail in others, and as you've noticed, the failures are often pushed downstream where the error messages are less than helpful.

Years ago, NCrunch had internal restrictions that would prevent any workspace file from exceeding the 259 character path limit. This was later delegated to the platform itself to assess since people were rightly complaining about situations where NCrunch was rejecting long paths that their toolset was otherwise able to work with. So now we have part of the platform that accepts the path, then another part of the platform downstream quietly fails because of it, then a later part throws up a weird error.

If there's a way to make this better without unintentionally making it much, much worse, I haven't been able to find it.

There's broadly two things you can do to shorten the paths involved. One is messy and easy: Set the workspace base path to C:\WS, so it's as close to the disk root as possible.

The second is harder. If you look at the workspace, you'll notice that NCrunch tends to pack it upwards to keep relative paths intact. For example, if you have a project at:
'c:\Dir1\Dir2\Solution\Project\Project.csproj' which references a dependency at 'c:\Dir1\OtherDir\MyFile.txt', the project path will be C:\WS\123\1\Dir2\Solution\Project.csproj.

If you're able to find relative dependencies that require this padding and move them closer to the project referencing them, you can make the workspace paths smaller.

I'm adjusting the documentation page you linked to suggest that path length issues may not have clear error messages attached to them, and to always check paths lengths when build issues don't make sense.
1 user thanked Remco for this useful post.
nikize on 6/3/2026(UTC)
nikize
#8 Posted : Wednesday, June 3, 2026 12:57:43 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/15/2025(UTC)
Posts: 7
Location: Sweden

Thanks: 7 times
Was thanked: 1 time(s) in 1 post(s)
Thanks for the extensive explanation.
Yes I could probably handle the remaining case with a even shorter path, while unfortunately current project does not really allow for me to move things around or rename.

My thinking of the documentation page is to under the "to long path" header have something like: "You might see things like: `System.IO.DirectoryNotFoundException: Could not find a part of the path`"
The reason for me being adamant about having the exception in the documentation is for one to actually see it and connect the two, because even if I read the page several times, i didn't connect this to the path length.
And the other is so that it has a better chance of showing up when posting that exception and stack to your favorite internet search engine.

As for the exception; When this message is shown
Code:

The file 'C:\dev\projpath\obj\Debug\netstandard2.0\projname.GlobalUsings.g.cs' could not be written to the workspace due to error: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\MyUser\AppData\Local\NCrunch\46876\35\projpartialpath\obj\Debug\netstandard2.0\projname.GlobalUsings.g.cs'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at nCrunch.Common.IO.FilePath.<>c__DisplayClass39_0.<WriteContent>b__0()

Catch System.IO.DirectoryNotFoundException, and extend the message with "The path length is x, expect issues at or below 260", this makes it easier to check for maximum path length.

Maybe what I propose below has already been tested?, if it does work, the above might be void ;)
HKLM\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled REG_DWORD is now enabled by default...
Manifest is needed to enable use of this(?):
https://learn.microsoft....re-long-path-capability

Code:

<configuration>
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPathsEnabled=true" />
</runtime>
</configuration>

https://learn.microsoft....long-paths-on-windows-10
Remco
#9 Posted : Thursday, June 4, 2026 12:33:20 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,555

Thanks: 1030 times
Was thanked: 1385 time(s) in 1286 post(s)
nikize;18816 wrote:

My thinking of the documentation page is to under the "to long path" header have something like: "You might see things like: `System.IO.DirectoryNotFoundException: Could not find a part of the path`"
The reason for me being adamant about having the exception in the documentation is for one to actually see it and connect the two, because even if I read the page several times, i didn't connect this to the path length.
And the other is so that it has a better chance of showing up when posting that exception and stack to your favorite internet search engine.


The documentation page has now been updated :)

nikize;18816 wrote:

Maybe what I propose below has already been tested?, if it does work, the above might be void ;)
HKLM\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled REG_DWORD is now enabled by default...
Manifest is needed to enable use of this(?):
https://learn.microsoft....re-long-path-capability

Code:

<configuration>
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPathsEnabled=true" />
</runtime>
</configuration>

https://learn.microsoft....long-paths-on-windows-10


The .config switch above only applies to older toolsets which aren't hosted on newer versions of .NET (i.e. VS2022 and earlier). Under VS2026, MSBuild is hosted by running dotnet.exe, which I believe is a native executable that has long paths already enabled. If you're seeing this under VS2026, that means that the error is probably being kicked up from a subprocess inside the build system which is almost entirely disconnected from NCrunch. MSBuild itself should generally be thought of as a process tree rather than a singleton, and some of those processes are shared between other build runs (i.e. VBCSCompiler.exe), so it gets really hard to make any guarantees about how the whole system will operate when making declarations at top level.

If you are running on an older toolset, you could try including this in the .config files for the nCrunch.BuildHost processes that are installed with NCrunch (usually at C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\Remco Software\NCrunch for Visual Studio 2022). Make sure you have the IDE closed when you do this. I would be interested to know if this solves the problem. If so, I can include the change in a future NCrunch build.
nikize
#10 Posted : Thursday, June 4, 2026 12:46:35 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/15/2025(UTC)
Posts: 7
Location: Sweden

Thanks: 7 times
Was thanked: 1 time(s) in 1 post(s)
This is on vs2026
Since we in the first case see nCrunch.Common.IO.FilePath in the stack, I assume that it is the ncrunch process that hits this, maybe there is other cases as well, but the first case shouldn't happen if long path support was working in the ncrunch process.
Remco
#11 Posted : Thursday, June 4, 2026 1:27:37 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,555

Thanks: 1030 times
Was thanked: 1385 time(s) in 1286 post(s)
nikize;18819 wrote:
This is on vs2026
Since we in the first case see nCrunch.Common.IO.FilePath in the stack, I assume that it is the ncrunch process that hits this, maybe there is other cases as well, but the first case shouldn't happen if long path support was working in the ncrunch process.


Agreed. I will check this.
1 user thanked Remco for this useful post.
nikize on 6/4/2026(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.064 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download