7

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.

5 Answers 5

4

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

5 Comments

Thanks for the answer Hari, Do I really need Storage Emulator? I am using vs code in mac and Storage Emulator is not present for mac I guess.
If using the Windows OS, Storage Emulator is required. If using the MacOS, Install Azurite in VS Code Extensions as well as the Microsoft Azure Storage Explorer to connect to local storage emulator
Hi, I followed all the steps but still not able to debug. I gave up on this problem. :(
As of Apr 26, 2022, the behavior in the OP video still occurs. I can get the debug process going, and it even runs the function app in the terminal. The problem is that the debug console does not attach to the function app, break points dont work, etc
Hello @AndrewPye, I have given all my inputs whatever I'm using to debug the Azure Function in Visual Studio code, and this is working to all my colleagues as well. Sometimes it throws errors in launch.json because of existing port running, in this case - run in the new port and needs to be corrected any mistakes in the code. Please follow the official documentation given and if the issue persists still, please mail to AzCommunity [at] microsoft dot com or raise a ticket in Azure Technical Support!
0

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.

Comments

0

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"
    }
  ]
}

1 Comment

While I'm not sure why this is a solution, or go into what the underlying problem is that this solves, this did the trick for me on windows 11 with azure function core tools 4.2.2.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.