vscode-azurefunctions icon indicating copy to clipboard operation
vscode-azurefunctions copied to clipboard

VS code azure powershell function debugging issue - Omnisharp Json Rpc exception

Open lavibhatnagar opened this issue 2 years ago • 19 comments

Environment: VS Code version: 1.68.0 C# Extension version: 1.25.0 Azure Core tools: v4 Powershell version: 7

Error: image

Steps to reproduce:

  1. Create azure powershell function
  2. Put a breakpoint anywhere and hit F5
  3. See error

Things Tried:

  1. uninstalling c# extension
  2. installing c# extension
  3. changed c# extension version
  4. removed extensionBundle section from host.json

lavibhatnagar avatar Jun 16 '22 11:06 lavibhatnagar

Thanks for reporting this. We can also reproduce this issue, so we'll start investigating.

Do you have any idea when this started occurring? Or has the debugger never worked for Powershell 7?

nturinski avatar Jun 23 '22 22:06 nturinski

@nturinski i have no idea since when this issue started occurring, i encountered this issue on 15 june.

lavibhatnagar avatar Jun 24 '22 07:06 lavibhatnagar

I'm running Mac M1 Pro Monterey 12.4 (21F79), this issue has been happening since around 25th May. I have played around with dot net core runtimes and SDKs v3 and v6 without success.

Screen Shot 2022-07-05 at 10 22 32 AM

I made some initial progress by changing FUNCTIONS_WORKER_RUNTIME_VERSION to 7.2 (from the default ~7), and this got the to where the local debugging seems to start and run the local functions, no errors in the console, however pops up the above image, and the local functions are not actually running/listening.

Azure Functions Core Tools
Core Tools Version:       4.0.4590 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.5.2.18383
Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  12.4
 OS Platform: Darwin
 RID:         osx.12-arm64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.300/

Host (useful for support):
  Version: 6.0.5
  Commit:  70ae3df4a6

.NET SDKs installed:
  6.0.300 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

adrwh avatar Jul 05 '22 14:07 adrwh

Hi

Is there any update on this?

lavibhatnagar avatar Jul 06 '22 15:07 lavibhatnagar

Could you provide any output from the Powershell Extension Logs and the Omnisharp Log output channels?

Based on this comment, I got it working by adding an empty main.cs file to the root of my workspace.

alexweininger avatar Jul 07 '22 23:07 alexweininger

I reinstalled the C# extension, and there seems to be improvement. I can now run a normal F5 debug without getting the Omnisharp popup, however it kinda feels like the debugger is not attached to anything, none of my breakpoints are being hit, but i am getting output from the functions.

Here is my launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "PowerShell Launch Current File",
      "type": "PowerShell",
      "request": "launch",
      "script": "${file}",
      "cwd": "${file}"
    },
    {
      "name": "Attach to PowerShell Functions",
      "type": "PowerShell",
      "request": "attach",
      "customPipeName": "AzureFunctionsPSWorker",
      "runspaceId": 1,
      "preLaunchTask": "func: host start --powershell --verbose"
    }
  ]
}

The OmniSharp Log is empty The PowerShell Extension Logs all look normal, no [Warning] or [Error] lines.

adrwh avatar Jul 08 '22 14:07 adrwh

I created a fresh Function from scratch from VS Code and ran F5, heres the output.

 *  Executing task: func host start 


Azure Functions Core Tools
Core Tools Version:       4.0.4590 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.5.2.18383


Functions:

        HttpTrigger1: [GET,POST] http://localhost:7071/api/HttpTrigger1

For detailed output, run func with --verbose flag.
[2022-07-08T14:24:18.668Z] Unhandled exception. System.TypeInitializationException: The type initializer for 'System.Management.Automation.Tracing.PSEtwLog' threw an exception.
[2022-07-08T14:24:18.668Z]  ---> System.TypeInitializationException: The type initializer for 'System.Management.Automation.Tracing.PSSysLogProvider' threw an exception.
[2022-07-08T14:24:18.669Z]  ---> System.DllNotFoundException: Unable to load shared library 'libpsl-native' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(liblibpsl-native, 0x0001): tried: 'liblibpsl-native' (no such file), '/usr/local/lib/liblibpsl-native' (no such file), '/usr/lib/liblibpsl-native' (no such file), '/Volumes/dev/functest/liblibpsl-native' (no such file)
[2022-07-08T14:24:18.669Z]    at System.Management.Automation.Tracing.NativeMethods.OpenLog(IntPtr ident, SysLogPriority facility)
[2022-07-08T14:24:18.669Z]    at System.Management.Automation.Tracing.SysLogProvider..ctor(String applicationId, PSLevel level, PSKeyword keywords, PSChannel channels)
[2022-07-08T14:24:18.669Z]    at System.Management.Automation.Tracing.PSSysLogProvider..cctor()
[2022-07-08T14:24:18.669Z]    --- End of inner exception stack trace ---
[2022-07-08T14:24:18.669Z]    at System.Management.Automation.Tracing.PSSysLogProvider..ctor()
[2022-07-08T14:24:18.669Z]    at System.Management.Automation.Tracing.PSEtwLog..cctor()
[2022-07-08T14:24:18.669Z]    --- End of inner exception stack trace ---
[2022-07-08T14:24:18.669Z]    at System.Management.Automation.Tracing.PSEtwLog.LogOperationalInformation(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, Object[] args)
[2022-07-08T14:24:18.669Z]    at System.Management.Automation.Remoting.RemoteSessionNamedPipeServer.ProcessListeningThread(Object state)
[2022-07-08T14:24:18.669Z]    at System.Threading.Thread.StartCallback()
[2022-07-08T14:24:18.718Z] Language Worker Process exited. Pid=29738.
[2022-07-08T14:24:18.718Z] dotnet exited with code 134 (0x86). Unhandled exception. System.TypeInitializationException: The type initializer for 'System.Management.Automation.Tracing.PSEtwLog' threw an exception.
[2022-07-08T14:24:18.774Z] Failed to start a new language worker for runtime: powershell.
[2022-07-08T14:24:18.774Z] System.Private.CoreLib: A task was canceled.
[2022-07-08T14:24:18.961Z] Unhandled exception. System.TypeInitializationException: The type initializer for 'System.Management.Automation.Tracing.PSEtwLog' threw an exception.
[2022-07-08T14:24:18.961Z]  ---> System.TypeInitializationException: The type initializer for 'System.Management.Automation.Tracing.PSSysLogProvider' threw an exception.
[2022-07-08T14:24:18.961Z]  ---> System.DllNotFoundException: Unable to load shared library 'libpsl-native' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(liblibpsl-native, 0x0001): tried: 'liblibpsl-native' (no such file), '/usr/local/lib/liblibpsl-native' (no such file), '/usr/lib/liblibpsl-native' (no such file), '/Volumes/dev/functest/liblibpsl-native' (no such file)
[2022-07-08T14:24:18.961Z]    at System.Management.Automation.Tracing.NativeMethods.OpenLog(IntPtr ident, SysLogPriority facility)
[2022-07-08T14:24:18.962Z]    at System.Management.Automation.Tracing.SysLogProvider..ctor(String applicationId, PSLevel level, PSKeyword keywords, PSChannel channels)
[2022-07-08T14:24:18.962Z]    at System.Management.Automation.Tracing.PSSysLogProvider..cctor()
[2022-07-08T14:24:18.962Z]    --- End of inner exception stack trace ---
[2022-07-08T14:24:18.962Z]    at System.Management.Automation.Tracing.PSSysLogProvider..ctor()
[2022-07-08T14:24:18.962Z]    at System.Management.Automation.Tracing.PSEtwLog..cctor()
[2022-07-08T14:24:18.962Z]    --- End of inner exception stack trace ---
[2022-07-08T14:24:18.962Z]    at System.Management.Automation.Tracing.PSEtwLog.LogOperationalInformation(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, Object[] args)
[2022-07-08T14:24:18.962Z]    at System.Management.Automation.Remoting.RemoteSessionNamedPipeServer.ProcessListeningThread(Object state)
[2022-07-08T14:24:18.962Z]    at System.Threading.Thread.StartCallback()
[2022-07-08T14:24:18.995Z] Language Worker Process exited. Pid=29743.
[2022-07-08T14:24:18.995Z] dotnet exited with code 134 (0x86). Unhandled exception. System.TypeInitializationException: The type initializer for 'System.Management.Automation.Tracing.PSEtwLog' threw an exception.
[2022-07-08T14:24:23.355Z] Host lock lease acquired by instance ID '00000000000000000000000021AF8539'.
[2022-07-08T14:24:29.296Z] Unhandled exception. System.TypeInitializationException: The type initializer for 'System.Management.Automation.Tracing.PSEtwLog' threw an exception.
[2022-07-08T14:24:29.296Z]  ---> System.TypeInitializationException: The type initializer for 'System.Management.Automation.Tracing.PSSysLogProvider' threw an exception.
[2022-07-08T14:24:29.296Z]  ---> System.DllNotFoundException: Unable to load shared library 'libpsl-native' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(liblibpsl-native, 0x0001): tried: 'liblibpsl-native' (no such file), '/usr/local/lib/liblibpsl-native' (no such file), '/usr/lib/liblibpsl-native' (no such file), '/Volumes/dev/functest/liblibpsl-native' (no such file)
[2022-07-08T14:24:29.296Z]    at System.Management.Automation.Tracing.NativeMethods.OpenLog(IntPtr ident, SysLogPriority facility)
[2022-07-08T14:24:29.296Z]    at System.Management.Automation.Tracing.SysLogProvider..ctor(String applicationId, PSLevel level, PSKeyword keywords, PSChannel channels)
[2022-07-08T14:24:29.296Z]    at System.Management.Automation.Tracing.PSSysLogProvider..cctor()
[2022-07-08T14:24:29.296Z]    --- End of inner exception stack trace ---
[2022-07-08T14:24:29.296Z]    at System.Management.Automation.Tracing.PSSysLogProvider..ctor()
[2022-07-08T14:24:29.296Z]    at System.Management.Automation.Tracing.PSEtwLog..cctor()
[2022-07-08T14:24:29.296Z]    --- End of inner exception stack trace ---
[2022-07-08T14:24:29.296Z]    at System.Management.Automation.Tracing.PSEtwLog.LogOperationalInformation(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, Object[] args)
[2022-07-08T14:24:29.296Z]    at System.Management.Automation.Remoting.RemoteSessionNamedPipeServer.ProcessListeningThread(Object state)
[2022-07-08T14:24:29.297Z]    at System.Threading.Thread.StartCallback()
[2022-07-08T14:24:29.329Z] Language Worker Process exited. Pid=29750.
[2022-07-08T14:24:29.329Z] dotnet exited with code 134 (0x86). Unhandled exception. System.TypeInitializationException: The type initializer for 'System.Management.Automation.Tracing.PSEtwLog' threw an exception.
[2022-07-08T14:24:29.329Z] Exceeded language worker restart retry count for runtime:powershell. Shutting down and proactively recycling the Functions Host to recover
 *  Terminal will be reused by tasks, press any key to close it. 

adrwh avatar Jul 08 '22 14:07 adrwh

{ "version": "0.2.0", "configurations": [ { "name": "PowerShell Launch Current File", "type": "PowerShell", "request": "launch", "script": "${file}", "cwd": "${file}" }, { "name": "Attach to PowerShell Functions", "type": "PowerShell", "request": "attach", "customPipeName": "AzureFunctionsPSWorker", "runspaceId": 1, "preLaunchTask": "func: host start --powershell --verbose" } ] }

Tried same thing but i am still getting same error. reinstalled c# extension. image

Tried with freashly created function. still same error. image

lavibhatnagar avatar Jul 08 '22 14:07 lavibhatnagar

Hi all,

I was running into the OmniSharp.Extensions.JsonRpc.RpcErrorException as well. After installing PowerShell 7.2 however, it seems to be attaching correctly:

image

Note that func host start still threw an error, but I hit "debug anyway"

Could you run $PSversionTable in the terminal that VS Code is running and verify the version number?

image

nturinski avatar Jul 14 '22 22:07 nturinski

Hi nturinski,

Yes, if you hit run on script debugger is getting attached which was happening it before.

image

Main Issue is when you try to hit F5 or press green button, func host will start and soon will throw the error mentioned above. image

Here is my powershell integrated console version image

Can we please get the solution soon?

lavibhatnagar avatar Jul 15 '22 15:07 lavibhatnagar

Hi lavibhatnagar, hitting F5 does work for me and attaches to the PS trigger for me. The only other thing that I tried was having a main.cs file in the root of my directory. It can be an empty file.

Unfortunately, this doesn't seem like something that our extension can fix directly, but I will keep working with you to try to figure out a workaround/solution.

nturinski avatar Jul 15 '22 18:07 nturinski

Hi @nturinski

i tried with creating new main.cs file in root directory. but still i am getting same error.

Are you able to make a request to function? i can only run the code if i run the script. all other option seems not working for me, image

lavibhatnagar avatar Jul 18 '22 08:07 lavibhatnagar

For me, I can run "func host start" manually and get function output, but i cannot use breakpoints. If i try to run F5, i get ugly error messages Result: ERROR: Unable to find type [HttpStatusCode], which sounds like it cannot load the underlying libraries.

adrwh avatar Jul 18 '22 14:07 adrwh

Hello, the issue can be fixed by changing your default Powershell Integrated Console to version 7 in vscode settings.json: "terminal.integrated.profiles.windows": { ..... "Powershell 7":{ "path": "C:\Program Files\PowerShell\7\pwsh.exe", "icon": "terminal-powershell" } }, "terminal.integrated.defaultProfile.windows": "Powershell 7",

jzu55 avatar Jul 27 '22 14:07 jzu55

Hello, the issue can be fixed by changing your default Powershell Integrated Console to version 7 in vscode settings.json: "terminal.integrated.profiles.windows": { ..... "Powershell 7":{ "path": "C:\Program Files\PowerShell\7\pwsh.exe", "icon": "terminal-powershell" } }, "terminal.integrated.defaultProfile.windows": "Powershell 7",

This one is not working for me....

yirmio avatar Jul 27 '22 18:07 yirmio

Hello, the issue can be fixed by changing your default Powershell Integrated Console to version 7 in vscode settings.json: "terminal.integrated.profiles.windows": { ..... "Powershell 7":{ "path": "C:\Program Files\PowerShell\7\pwsh.exe", "icon": "terminal-powershell" } }, "terminal.integrated.defaultProfile.windows": "Powershell 7",

This one is not working for me....

Same. Not working for me either

lavibhatnagar avatar Jul 28 '22 08:07 lavibhatnagar

Hello, the issue can be fixed by changing your default Powershell Integrated Console to version 7 in vscode settings.json: "terminal.integrated.profiles.windows": { ..... "Powershell 7":{ "path": "C:\Program Files\PowerShell\7\pwsh.exe", "icon": "terminal-powershell" } }, "terminal.integrated.defaultProfile.windows": "Powershell 7",

This one is not working for me....

Same. Not working for me either

Have you installed PS7? https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.2

kteamkay avatar Aug 14 '22 09:08 kteamkay

Installing .Net Core 3.1, x86 worked for me: https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-3.1.29-windows-x86-installer

allanreyes avatar Sep 14 '22 04:09 allanreyes

Hello, the issue can be fixed by changing your default Powershell Integrated Console to version 7 in vscode settings.json: "terminal.integrated.profiles.windows": { ..... "Powershell 7":{ "path": "C:\Program Files\PowerShell\7\pwsh.exe", "icon": "terminal-powershell" } }, "terminal.integrated.defaultProfile.windows": "Powershell 7",

This one is not working for me....

Same. Not working for me either

Have you installed PS7? https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.2

yes.....

yirmio avatar Sep 14 '22 04:09 yirmio

What fixed the problem for me, was to install this: https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-desktop-3.1.29-windows-x64-installer

It's important that it's the Desktop version - other versions did NOT solve the problem.

gammelgaard52 avatar Oct 03 '22 09:10 gammelgaard52

Hello, the issue can be fixed by changing your default Powershell Integrated Console to version 7 in vscode settings.json: "terminal.integrated.profiles.windows": { ..... "Powershell 7":{ "path": "C:\Program Files\PowerShell\7\pwsh.exe", "icon": "terminal-powershell" } }, "terminal.integrated.defaultProfile.windows": "Powershell 7",

I also had to update "powershell.powerShellDefaultVersion" from "Windows PowerShell (x64)" to "Windows PowerShell"

misteriks avatar Oct 08 '22 16:10 misteriks

I have installed dot net runtime windows installer (x64) and also updated PS 7 veriosn to the latest, and it did fixed the issue.

Thanks @gammelgaard52 @kteamkay

https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-desktop-3.1.29-windows-x64-installer

lavibhatnagar avatar Oct 21 '22 13:10 lavibhatnagar

same issue for me, and nothing here works. PowerShell 7.2 PowerShell v4 Function

Same error. The function host starts. grpc error comes up, VS Code debugger doesn't attach.

davidobrien1985 avatar Dec 12 '22 23:12 davidobrien1985

I was able to resolve this to update extensionBundle in host.josn to: { "version": "2.0", "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[3.3.0, 4.0.0)" } }

After restarting VSCode it worked again

cemmetje87 avatar Dec 14 '22 16:12 cemmetje87

I was able to resolve this to update extensionBundle in host.josn to: { "version": "2.0", "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[3.3.0, 4.0.0)" } }

After restarting VSCode it worked again

Can anyone else confirm that updating the extension bundle resolves the issue for them?

nturinski avatar Mar 02 '23 23:03 nturinski

Hey, in my case under the hood, VS code used Powershell 5, I installed the newest version from MS site and everything started working

Name                           Value
----                           -----
PSVersion                      7.3.3
PSEdition                      Core
GitCommitId                    7.3.3
OS                             Microsoft Windows 10.0.20348
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PiotrWachulec avatar Mar 06 '23 11:03 PiotrWachulec

For anyone still experiencing this issue, users have reported another fix here -> https://github.com/OmniSharp/omnisharp-vscode/issues/5279#issuecomment-1279154964

alexweininger avatar Mar 23 '23 15:03 alexweininger

Hey guys in my case I had the same issue with that OmniSharp extension, In my case I saw that I had an error behind it, and was due the azure-core-tools package wasn't updated so I did the update as first step.

The I tried to run my function again and the problem persisted but this time the error behind changed, it said that my dotnet SDK was the version 7 and the core tools needed the version 6. So, I did the installation of the .NET DSK v6.

Now I'm able to execute my function and use the full capabilities of the debugger.

manuelpazprad avatar Oct 05 '23 15:10 manuelpazprad