Azure-Functions icon indicating copy to clipboard operation
Azure-Functions copied to clipboard

Unable to run and debug function app in VS Code

Open liliankasem opened this issue 3 years ago • 13 comments

Function App name

N/A - local

Tools used

  • VS Code
  • Azure Functions VS Code Extension v1.5.2
  • dotnet --version = 6.0.100-rc.2.21505.57
  • func --version = 4.0.3780

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 avatar Oct 21 '21 21:10 liliankasem

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

liliankasem avatar Oct 22 '21 22:10 liliankasem

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

AdamCoulterOz avatar Nov 25 '21 11:11 AdamCoulterOz

@nturinski might be able to help here.

anthonychu avatar Nov 25 '21 20:11 anthonychu

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

AdamCoulterOz avatar Nov 27 '21 10:11 AdamCoulterOz

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

nturinski avatar Nov 29 '21 20:11 nturinski

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

AdamCoulterOz avatar Nov 30 '21 07:11 AdamCoulterOz

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)

liliankasem avatar Nov 30 '21 11:11 liliankasem

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

josmithua avatar Dec 13 '21 15:12 josmithua

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

nturinski avatar Dec 21 '21 01:12 nturinski

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

any updates on this @nturinski ? ☺️

AdamCoulterOz avatar Jan 31 '22 04:01 AdamCoulterOz

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 ?

Arash-Sabet avatar Feb 03 '22 12:02 Arash-Sabet

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.

nturinski avatar Feb 03 '22 22:02 nturinski

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

AdamCoulterOz avatar Feb 07 '22 03:02 AdamCoulterOz

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)

johnnyreilly avatar Nov 11 '22 19:11 johnnyreilly