Azure / Azure-Functions

1.11k stars 198 forks source link

Unable to run and debug function app in VS Code #2071

Open liliankasem opened 3 years ago

liliankasem commented 3 years ago

Function App name

N/A - local

Tools used

New V4 app or existing V3 app migrated to V4

New v4 app - dotnet in-proc

Issue

After creating a new v4 app (.net v6 in-proc) using the functions VS Code extension, I am not able to run and debug the function app with the .vscode configuration that was added by the template. The application runs fine and as expected when using cli i.e. func start. My assumption here is that the templated .vscode config is wrong?

Expected

Pressing F5 in VS Code after a newly generated function app with VS Code config should build and run the function application in debug mode

Actual

Pressing F5 in VS Code after a newly generated function app with VS Code config builds and runs the function app, which then shuts down immediately after

Screen Shot 2021-10-21 at 2 19 09 PM
liliankasem commented 3 years ago

Might be worth mentioning that this works as expected when creating a new v4 dotnet isolated app, hitting F5 builds and runs the function app without crashing

AdamCoulterOz commented 2 years ago

I'm having this same issue with the GA release also ...

dotnet v6.0.100
func v4.0.3971
code v1.62.3
ms-dotnettools.csharp v1.23.16
ms-azuretools.vscode-azurefunctions v1.6.0
Microsoft.NET.Sdk.Functions v4.0.1
anthonychu commented 2 years ago

@nturinski might be able to help here.

AdamCoulterOz commented 2 years ago

@nturinski please help ... hard to work without this

nturinski commented 2 years ago

I was able to debug with the template HTTP Trigger using .NET 6 without altering anything. My environment configuration is listed below.

From the original post, the error seems like it's having an issue creating directories in the /dev/ folder. Are you using a remote workspace or VS Code online by chance?

OS: win32
OS Release: 10.0.19042
dotnet v6.0.100-rc.1.21463.6
func v4.0.3780
code v1.62.0-insider
ms-azuretools.vscode-azurefunctions v1.6.0
Microsoft.NET.Sdk.Functions v4.0.1

image

AdamCoulterOz commented 2 years ago

Do people actually still use windows to dev? haha 😛

@nturinski You've built it as an isolated, which @liliankasem said does work. I believe we are both having problems with non-isolated (integrated? with the process worker). Also, its not a problem (for me) running the function host using core tools, it's that the vscode debugger attachment crashes... the func app keeps running, but vscode has no connection to it.

image

I also should've been more clear with my environment, I'm on macOS.

OS
ProductName:    macOS
ProductVersion: 12.0.1
BuildVersion:   21A559

dotnet v6.0.100
func v4.0.3971
func runtime v4.0.1.16815
code v1.62.3
ms-dotnettools.csharp v1.23.16
ms-azuretools.vscode-azurefunctions v1.6.0
Microsoft.NET.Sdk.Functions v4.0.1

The project is created entirely from the vscode new func project command, accepting all the defaults.

debug_func.csproj

<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>

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "<connectionStringToRealAzStorageAccount>",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
  }
}

launch.json

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

settings.json

{
    "azureFunctions.deploySubpath": "bin/Release/net6.0/publish",
    "azureFunctions.projectLanguage": "C#",
    "azureFunctions.projectRuntime": "~4",
    "debug.internalConsoleOptions": "neverOpen",
    "azureFunctions.preDeployTask": "publish (functions)"
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "clean (functions)",
            "command": "dotnet",
            "args": [
                "clean",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "type": "process",
            "problemMatcher": "$msCompile"
        },
        {
            "label": "build (functions)",
            "command": "dotnet",
            "args": [
                "build",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "type": "process",
            "dependsOn": "clean (functions)",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": "$msCompile"
        },
        {
            "label": "clean release (functions)",
            "command": "dotnet",
            "args": [
                "clean",
                "--configuration",
                "Release",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "type": "process",
            "problemMatcher": "$msCompile"
        },
        {
            "label": "publish (functions)",
            "command": "dotnet",
            "args": [
                "publish",
                "--configuration",
                "Release",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "type": "process",
            "dependsOn": "clean release (functions)",
            "problemMatcher": "$msCompile"
        },
        {
            "label": "launch",
            "type": "func",
            "dependsOn": "build (functions)",
            "options": {
                "cwd": "${workspaceFolder}/bin/Debug/net6.0"
            },
            "command": "host start",
            "isBackground": true,
            "problemMatcher": "$func-dotnet-watch"
        }
    ]
}
liliankasem commented 2 years ago

I was able to debug with the template HTTP Trigger using .NET 6 without altering anything. My environment configuration is listed below.

From the original post, the error seems like it's having an issue creating directories in the /dev/ folder. Are you using a remote workspace or VS Code online by chance?

OS: win32
OS Release: 10.0.19042
dotnet v6.0.100-rc.1.21463.6
func v4.0.3780
code v1.62.0-insider
ms-azuretools.vscode-azurefunctions v1.6.0
Microsoft.NET.Sdk.Functions v4.0.1

image

Nope, running vs code local on a mac and in-proc (no issues with the isolated template)

josmithua commented 2 years ago

Same here. macOS, azure-functions-core-tools@4, trying to debug the .NET 6 (non isolated) template:

https://user-images.githubusercontent.com/3375071/145839127-20c61290-94a0-4276-9db4-f37c8056d7e8.mov

nturinski commented 2 years ago

Sorry for the late reply all-- I was out for the holidays. I'll start investigating this now.

AdamCoulterOz commented 2 years ago

Sorry for the late reply all-- I was out for the holidays. I'll start investigating this now.

any updates on this @nturinski ? ☺️

Arash-Sabet commented 2 years ago

This issue is happening for dotnet-isolated functions in macOS Monterey 12.2 with M1 Pro chip. This workaround never worked. Any updates on a fix or workaround @nturinski ?

nturinski commented 2 years ago

Hi @Arash-Sabet

For any M1 issues, the Core tools team has a roll-up issue tracking it here: https://github.com/Azure/azure-functions-core-tools/issues/2834. Unfortunately, I'm not sure if there's anything we can do on the tooling side to fix this as we just core tools and attach.

If you're not using an M1, I think that the workaround cited above should work. Sorry, we haven't had the bandwidth to implement this in the extension.

I know this has been a major pain in the butt and has affected productivity. I'm really sorry about, we will try to get this resolved soon.

AdamCoulterOz commented 2 years ago

@nturinski - it looks like https://github.com/OmniSharp/omnisharp-vscode/issues/4903 is actually a duplicate of this issue. I'm at least not using M1.

Is this a problem with the Azure Functions runtime or the OmniSharp language server?

johnnyreilly commented 1 year ago

I've needed to refer back to @basilfx's workaround so often that I've turned it into a blog post here: https://johnnyreilly.com/debugging-azure-functions-vs-code-mac-os (credit attributed to @basilfx)

fernandezafb commented 1 year ago

I having the same problem @nturinski. I'm using an intel based mac 12.6.3, not M1. Exactly same problem. The signer workaround didn't work for me. This is indeed a pain in the but as we can't debug using VS Code.

DZwell commented 1 year ago

I've needed to refer back to @basilfx's workaround so often that I've turned it into a blog post here: https://blog.johnnyreilly.com/2022/11/11/debugging-azure-functions-vs-code-mac-os (credit attributed to @basilfx)

Huzzah! This fixed me, at least for now. Thank you for this blog post! Needing to litter the code with Console.WriteLine to figure out what's going on is no fun.