Skip to content

Unhanlded exception if CWD is deleted #53443

Open

Description

@eerhardt

Describe the bug

When the current working directory is deleted (say in another tab), the dotnet commands stop working.

To Reproduce

  1. Open 2 command prompts
  2. In prompt 1, cd into a new directory - ~/DotNetTest
  3. In prompt 2, delete that directory
  4. In prompt 1, execute dotnet nuget locals http-cache -c

Exceptions (if any)

System.TypeInitializationException: The type initializer for 'Microsoft.DotNet.Cli.Parser' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'Microsoft.DotNet.Cli.Commands.Test.TestCommandParser' threw an exception.
 ---> System.IO.FileNotFoundException: Unable to find the specified file.
   at Interop.Sys.GetCwdHelper(Byte* ptr, Int32 bufferSize)
   at Interop.Sys.GetCwd()
   at Microsoft.DotNet.Cli.Commands.Test.TestCommandDefinition.Create()
   at Microsoft.DotNet.Cli.Commands.Test.TestCommandParser.CreateCommand()
   at Microsoft.DotNet.Cli.Commands.Test.TestCommandParser..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.DotNet.Cli.Parser..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.DotNet.Cli.Parser.Parse(String[] args)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, TimeSpan startupTime)
   at Microsoft.DotNet.Cli.Program.Main(String[] args)

Further technical details

details of dotnet --info

.NET SDK: Version: 10.0.201 Commit: 4d3023de60 Workload version: 10.0.200-manifests.0793c108 MSBuild version: 18.3.0-release-26153-122+4d3023de6

Runtime Environment:
OS Name: ubuntu
OS Version: 24.04
OS Platform: Linux
RID: linux-x64
Base Path: /home/eerhardt/.dotnet/sdk/10.0.201/

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.5
Architecture: x64
Commit: a612c2a105

.NET SDKs installed:
10.0.201 [/home/eerhardt/.dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 10.0.5 [/home/eerhardt/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 10.0.5 [/home/eerhardt/.dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

- The IDE (VS / VS Code/ VS4Mac) you're running on, and its version

Activity

  1. added
    untriaged
    on Mar 13, 2026
  2. added this to the Backlog milestone on Mar 13, 2026
  3. removed
    untriaged
    on Mar 13, 2026
  4. mstefarov commented on May 15, 2026

    @mstefarov

    Just ran into this myself on MacOS. I had the terminal open in the output folder, called a command to clean the solution (which deleted the output folder), and ended up in a "missing working directory" situation. Any dotnet command I typed there (even dotnet --version) gave me this exact error until I changed to an outer directory.

    dotnet info output (10.0.300)
    me@machine / % dotnet --info
    .NET SDK:
     Version:           10.0.300
     Commit:            caa81fa497
     Workload version:  10.0.300.1
     MSBuild version:   18.6.3+caa81fa49
    
    Runtime Environment:
     OS Name:     Mac OS X
     OS Version:  26.4
     OS Platform: Darwin
     RID:         osx-arm64
     Base Path:   /usr/local/share/dotnet/sdk/10.0.300/
    
    .NET workloads installed:
     [maui]
       Installation Source: SDK 10.0.300
       Manifest Version:    10.0.20/10.0.100
       Manifest Path:       /usr/local/share/dotnet/sdk-manifests/10.0.100/microsoft.net.sdk.maui/10.0.20/WorkloadManifest.json
       Install Type:        FileBased
    
     [android]
       Installation Source: SDK 10.0.300
       Manifest Version:    36.1.53/10.0.100
       Manifest Path:       /usr/local/share/dotnet/sdk-manifests/10.0.100/microsoft.net.sdk.android/36.1.53/WorkloadManifest.json
       Install Type:        FileBased
    
    Configured to use workload sets when installing new manifests.
    
    Host:
      Version:      10.0.8
      Architecture: arm64
      Commit:       94ea82652c
    
    .NET SDKs installed:
      10.0.300 [/usr/local/share/dotnet/sdk]
    
    .NET runtimes installed:
      Microsoft.AspNetCore.App 10.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.NETCore.App 10.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
    
    Other architectures found:
      None
    
    Environment variables:
      Not set
    
    global.json file:
      Not found
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions