Unknown
Unknown

Reputation: 437

Not able to debug Azure Functions in Visual Studio Code. Debugger stops

I am using http trigger Azure Function. When I am running my application (by pressing F5), after clicking http://localhost:7071/api/HttpTrigger1, I am getting response in browser but code doesn't stop at breakpoints.

After careful observation, I saw that debugger starts for 0.5 seconds and closes automatically.

I have posted the video here. At 5th second, we can see that debugger starts but closes instantly (Orange screen at 5th second).

There is a similar question on Stackoverflow, but that didn't solve my problem.

Upvotes: 7

Views: 11539

Answers (5)

Nazir A
Nazir A

Reputation: 111

Open User Settings (JSON) file, and add below entry. This worked for me, hopefully it will also work for others.

"azureFunctions.pickProcessTimeout": 180

Note: Default timeout is 60, and we changed it to 180.

Upvotes: 0

dot
dot

Reputation: 15660

In my case, I'm running on a mac. and this answer worked: https://github.com/OmniSharp/omnisharp-vscode/issues/4900

Basically I changed my launch.json from:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach to .NET Functions",
      "type": "coreclr",
      "request": "attach",
      "processId": "${command:azureFunctions.pickProcess}"
    }
  ]
}

to this:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach to .NET Functions",
      "type": "coreclr",
      "request": "attach",
      "processId": "${command:azureFunctions.pickProcess}",
      "targetArchitecture": "x86_64"
    }
  ]
}

Upvotes: 0

NoamStolero
NoamStolero

Reputation: 96

I have a similar issue.

I have multiple python azure function repositories which i work on in vs-code. If a file open in the editor has errors (lint errors, mypy errors, etc..) Whenever i try to launch a debug session the function starts but eventually detach from the debug session. After this log print:
INFO: Detaching console logging. Then it won't stop at breakpoints and log debug logs.

Unfortunately I don't have a solution yet. I do have a working workaround you can try:
Close any open file which has an error (you can close all the files), and launch the debug session (f5), I found this way it's working, stopping at breakpoints and not detaching the debugger.

If you (or anyone) find a working solution please share.

Upvotes: 0

Halmg
Halmg

Reputation: 41

I have experienced the same, while debugging Azure Functions in VS Code on a Mac. I found this open issue on the Omnisharp GitHub about this issue:

https://github.com/OmniSharp/omnisharp-vscode/issues/4903

In the end, basilfx's workaround ended up helping me:

I was triggered by a log line about code signing in the logging above. I therefore tried the following:

  • Create self-signed code signing certificate: https://stackoverflow.com/a/58363510/1423623
  • Navigate to the debugger folder (in my case, ~/.vscode/extensions/ms-dotnettools.csharp-1.24.4-darwin-x64/.debugger/x86_64)
  • Run codesign --remove-signature vsdbg-ui && codesign --remove-signature vsdbg
  • Run codesign -s my-codesign-cert vsdbg-ui && codesign -s my-codesign-cert vsdbg

I can now attach to a running instance of ./vsdbg-ui --server --consoleLogging --engineLogging from VS Code that stops at breakpoints. It's a work-around, but it shows something is wrong with the code signing of vsdbg and/or vsdbg-ui.

2022-04-20: can confirm that this still works, using OmniSharp 1.24.4.

Upvotes: 4

anon
anon

Reputation:

Prerequisites to run/debug the Azure Functions in Visual Studio Code:

  1. Azure Tools Extension

  2. Azure Functions Core Tools

  3. Also, Ensure that the Storage Emulator installed on your system, even it is deprecated but still used for local environment debugging and testing purposes

  4. Azurite Extension on VS Code Extensions Menu


local.settings.json

{  
"IsEncrypted": false,    
"Values": {    
"AzureWebJobsStorage": "UseDevelopmentStorage=true",    
"FUNCTIONS_WORKER_RUNTIME": "dotnet"  
}
}

.csproj file:

<Project  Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference  Include="Microsoft.NET.Sdk.Functions"  Version="4.0.1"  />
</ItemGroup>
<ItemGroup>
<None  Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None  Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>

Debug Result:

enter image description here

Put a breakpoint at some code line inside the Run Method and Start debugging.

All the code files and debugging video is available in the GitHub Repository and debugging video, please compare each file to your code.


As specified in this VS Code Official Documentation, need to install the language runtime extension for debugging purposes like C# for .NET, Python, Java, JavaScript, PowerShell etc.

For example, for the above .NET Azure Functions Project I have installed this extension in VS Code:

VS Code Extensions

Links to Install these extensions are given in prerequisites and in hyperlink wording formats.

References of VS Code debugging the Azure Functions:

  1. Debugging Azure Functions Locally in VS Code
  2. Microsoft Official Documentation of Azure Functions debugging in VS Code

Upvotes: 2

Related Questions