[Solved] OmniSharp RpcErrorException in VS Code Dev Containers for PowerShell-based Azure Functions
I recently got into VS Code Dev Containers and Azure Functions, and I love them. Unfortunately, the PowerShell Azure Functions pretty much come out of the box with a high likelihood of throwing Ominsharp exceptions when debugging.
Two of the files the setup process generates, launch.json
and tasks.json
, use the func Azure Function type.
launch.json
1{
2 "version": "0.2.0",
3 "configurations": [
4 {
5 "name": "Attach to PowerShell Functions",
6 "type": "PowerShell",
7 "request": "attach",
8 "customPipeName": "AzureFunctionsPSWorker",
9 "runspaceId": 1,
10 "preLaunchTask": "func: host start"
11 }
12 ]
13}
tasks.json
1{
2 "version": "2.0.0",
3 "tasks": [
4 {
5 "type": "func",
6 "command": "host start",
7 "problemMatcher": "$func-powershell-watch",
8 "isBackground": true
9 }
10 ]
11}
Fixed code
Initially, I reduced the number of OmniSharp errors by changing the PowerShell path in various config files, but it wasn't 100% effective. After running into the exception one too many times, I searched for a solution yet again and finally found the post I needed.
This GitHub comment provided the solution, which was initially found on StackOverflow. It took me so long to find this solution, I wanted to repost it for everyone's future reference.
Ultimately, the Azure Function type should be changed from func
to shell
. Here's what I finally ended up on:
launch.json
1{
2 "version": "0.2.0",
3 "configurations": [
4 {
5 "name": "Attach to PowerShell Functions",
6 "type": "PowerShell",
7 "request": "attach",
8 "customPipeName": "AzureFunctionsPSWorker",
9 "runspaceId": 1,
10 "processId": "${command:azureFunctions.pickProcess}",
11 "preLaunchTask": "func: host start"
12 }
13 ]
14}
tasks.json
1{
2 "version": "2.0.0",
3 "tasks": [
4 {
5 "label": "func: host start",
6 "type": "shell",
7 "command": "func host start --powershell --verbose",
8 "problemMatcher": "$func-powershell-watch",
9 "isBackground": true,
10 "options": {
11 "cwd": "${workspaceFolder}/functions"
12 }
13 }
14 ]
15}
So far, this change has solved 100% of my OminiSharp crashes.