Skip to content

Debugger restart leaves Azure Functions process or port in use (Attach to .NET, VS Code) #4416

@bueno12223

Description

@bueno12223

Issue Summary

When working with Azure Functions in .NET (isolated process) in Visual Studio Code, using the "Attach to .NET Functions" debugger configuration, the "Restart" button leaves the original function host process or debugger in an inconsistent state.

This causes two major issues:

  1. The ports used by the function (e.g., 7071 or 7100) are still occupied.
  2. The DLL files are locked by zombie .NET Host processes, leading to MSBuild errors during rebuild.

Steps to Reproduce

  1. Run an Azure Function (isolated .NET 8) locally in VS Code.
  2. Attach to the function using this launch.json config:
{
  "name": "Attach to .NET Functions",
  "type": "coreclr",
  "request": "attach",
  "processId": "${command:azureFunctions.pickProcess}"
}

Click the "Restart" button in the debugger.
VS Code throws:
No process with the specified ID is currently running..
After restart:

The port (7071 or 7100) is still in use.
Rebuilding the project fails with:

MSB3027: Could not copy "...az.dll"
The file is locked by: ".NET Host (PID 10020)"

Workaround

Kill the zombie process manually:

Or kill all dotnet processes:
taskkill /IM dotnet.exe /F

Or restart VS Code completely.

Expected Behavior

Clicking "Restart" should properly detach and re-attach the debugger, cleaning up the old process and freeing any ports or file locks.

It should not leave .NET Host processes hanging or locked on the function DLL.

Environment

OS: Windows 11
VS Code: 1.98.2
Azure Functions Core Tools: 4.0.6821
Azure Functions Extension: 1.16.3
.NET SDK: 8.0.101
Runtime: .NET Isolated
Func port: 7071 / 7100 (default)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions