Attach to debugger for Azure Functions from Rider on Mac - c#

Just wondering if anyone has managed to attach and debug an Azure Functions app using JetBrains Rider?
There only seems to be 2 debug options for Azure Functions
--debug VS
--debug VsCode
Not sure if Rider can attach to these, I can't find much on this. So if anyone else has succeeded please let me know how/if it can be done.
Thanks.

No, this is not possible to date (4. Oct. 2018):
According to the Rider online bug report (This is not implemented yet, please feel free to vote for https://youtrack.jetbrains.com/issue/RIDER-1256) this is not solved, yet.

The above issue has now been resolved, however it still does not support Azure Functions.
However I did find this, please note this appears to be windows only, not Mac.
https://github.com/JetBrains/azure-tools-for-intellij/issues/78#issuecomment-439313762
Install the Azure functions command line tools using NPM (https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local)
Add a file Properties/launchSettings.json, with the following contents (tailored to your project):
{
"profiles": {
"functions": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "%APPDATA%\\npm\\node_modules\\azure-functions-core-tools\\bin\\func.dll host start --port 7071 --pause-on-error",
"environmentVariables": {
"AZURE_FUNCTIONS_ENVIRONMENT": "Development",
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
}
}
}
}
Run the launch profile, and wait for the functions host to say it is running
In Rider, attach to the process using Run | Attach to Process.... Find the process that is running dotnet ... func.dll:

Related

Why might OnAfterRender not fire?

Similar to this question from two years ago, I have a Blazor server-side app and the OnAfterRender() method isn't firing. If I set a breakpoint at the start of the method, the breakpoint isn't hit.
I created a minimal example page in my project:
#page "/index2"
<h3>Index2</h3>
<p>Message: #msg</p>
#code {
private string msg = "Hello";
private bool flag = false;
protected override void OnAfterRender(bool firstRender)
{
if (!flag)
{
msg += " world";
flag = true;
StateHasChanged();
}
}
}
When I load this page, it displays "Message: Hello", without the "world" part ever appearing.
This is a project I haven't touched since in three months, and it worked perfectly a month ago. The only change I can think of is that I upgrading my OS to Windows 11. I have not tried running my project on Windows 10 yet; that may be my next attempt, but I'm hoping someone here has a more logical explanation. (Without a convincing reason why my OS would have an impact, that feels a bit like "magical thinking").
My _Host.cshtml has this as the final line in its body: <script src="_framework/blazor.server.js"></script>
My Startup.cs file has this as its last command in its Configure() method:
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
My project targets .NET 6.0.
The frustrating thing is that I've spent 19 months on this project and it all worked beautifully. I upgraded from Visual Studio 2019 to Visual Studio 2022 and it still worked. It just suddenly stopped working after I upgraded my operating system to Windows 11.
What I've tried:
I tried the solutions suggested for this question and verified that my _Host.cshtml and Startup.cs had the code suggested there (which both already did).
I tried uninstalling Visual Studio 2022 and reverting to Visual Studio 2019. My project no longer loaded in Visual Studio 2019 because my installed version of MSBuild had changed, and I remembered that I had previously had the project working in Visual Studio 2022, so reverting there was probably a dead end anyway.
I tried creating a completely fresh Blazor project, and in that fresh project the OnAfterRender() method did work as expected! But I'm completely flummoxed as to what could have broken in this preexisting project.
Edit: This seems to be a SignalR issue. In the debug output, I get this error message:
Microsoft.Azure.SignalR.ServiceConnection: Error: Failed to connect to
'(Primary)https://myproject-blazorservice-abc.service.signalr.net',
will retry after the back off period. Error detail: The server returned
status code '502' when status code '101' was expected..
My launchSettings.json file looked like this:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:9385",
"sslPort": 44312
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.Azure.SignalR"
}
},
"MyProject": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.Azure.SignalR"
}
}
}
}
If I comment out the two lines referencing SignalR, that error message goes away and the pages load as expected. (When I created a fresh Blazor project, I noticed that the newly-created launchSettings.json did not have those two lines.)
Now, I don't know much about SignalR. My understanding is that it provides an API for real-time communication between client-side pages and server-side code. So I guess with SignalR not working, that communication broke down, such that the server side never got the message to run OnAfterRender(). Would that make sense?
This question suggests that the '502' status code might suggest an issue with an Azure account, which seems plausible; this app does connect to a SQL Server database on a friend's Azure account.
Take your code, paste it into index in a vanilla Blazor Server or WASM deployed project and it works. The OS version will make no difference. [Polite] There are things that you are telling us!
On OnAfterRender{async} usage, it should (in general) only be used to do JS interop stuff. The component has already rendered, why do something where you need to force it to render again! Anything that manipulates the component instance data and needs to call StateHasChanged to make it appear should be coded into the normal lifecycle events.
Well, I still don't know why this was broken, but I did fix the problem. Maybe this will help someone in the future.
I created a new Blazor project, copied all my files into it (with relevant changes for namespaces etc), and OnAfterRender async seemed to work. Looking at the differences between the two, I noticed that the launchSettings.json files were different, so I copied the code from the newer launchSettings.json and replaced the old code with that (again, with relevant changes for namespaces etc.). Boom, things are working now in my original project.
I'm not happy about this... this is programming by coincidence and magical thinking ... but my project works again.

vscode c# debugger was not attached within the expected time limit

I'm running vscode version 1.73.1
I have the following extensions installed on a new VM that sits behind a corporate proxy:
Microsoft C# v1.25.2
Azurite v3.20.1
Azure Functions v1.9.0
I have a C# Azure Functions project that I'd like to debug.
My tasks.json file contains the following:
{
"type": "func",
"dependsOn": "build (functions)",
"options": {
"cwd": "${workspaceFolder}/bin/Debug/net6.0"
},
"command": "host start --dotnet-isolated-debug",
"isBackground": true,
"problemMatcher": "$func-dotnet-watch"
}
The launch.json is as follows:
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to .NET Functions",
"type": "coreclr",
"request": "attach",
"processId": "${command:azureFunctions.pickProcess}"
}
]
}
I click the debug icon from the sidebar menu and choose "Run and Debug - Attach to .Net Functions"
The function app is then build and starts. The VM is slow so it takes more than 60 seconds for the function app to start. During that time VS code pops up a message to say is it slow. However, the function app does start and the http endpoints are presented in green text.
I then see the following presented in the terminal window:
Azure Functions .NET Worker (PID: 12116) initialized in debug mode.
Waiting for debugger to attach... Host lock lease acquired by instance
ID '00000000000000000000000083B41702'. A debugger was not attached
within the expected time limit. The process will continue without a
debugger. Worker process started and initialized.
I don't see any text in the "Debug Console"
I am able to call the http endpoint and a successful response is returned, but the breakpoint does not break!
If I run the same solution in vs code directly on my laptop, then the debugger is attached. Problem is, I need to debug on the corporate VM because the code selects from an on-prem sql db.
So, I guess there must be some difference between the two configurations of vs code / extensions or perhaps the corporate proxy is causing a problem?
Not sure which text file this gets saved to but was able to resolve by extending the timeout in the workspace preferences section:
I increased from the default of 60 (seconds) to 180

The listener for function '' was unable to start. Azure durable function VS 2022

I am working in durable functions in Vs2022. it was all working fine till this noon. Suddenly it starts saying
The listener for function 'Orchestration' was unable to start.
DurableTask.AzureStorage: The response ended prematurely, with at
least 91 additional bytes expected. Microsoft.WindowsAzure.Storage:
The response ended prematurely, with at least 91 additional bytes
expected. System.Net.Http: The response ended prematurely, with at
least 91 additional bytes expected.
I really got confused what really happened to it which was working fine for more than couple of months.
Here is my local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"AzureWebJobsSecretStorageType": "files",
"environment": "Development",
}
}
My VS2022 version is 17.2.6
Kindly note, I am working in a company VM where I dont have any admin rights.
Your app running on Azurite and its not run on Older Azure Storage Emulator. its running newer version of Functions runtime. these effect your environment to seeing problems.
and you can try with older Azure Storage Emulator.
You have Storage Emulator on your machine checking on this location on your machine ProgramFile(x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe and try to run this emulator and run before staring debugging and see the issue it solved or not. if emulator already running then azurite won't be started.
Thank #cgillum for providing on solution on this issue.
More information about this issue please visit on these web page VS 2022 Local Debug Durable Functions Issues "Error in LeaseManagerStarter task. Exception: Microsoft.WindowsAzure.Storage.StorageException

VisualStudio Code csharp debugger generating error

I recently upgraded my version of VisualStudio Code to the latest release and am I getting an error when trying to debug csharp applications. I am running in windows 10 (14393) and am using vs code 1.23.1. I have an application that I created a few months ago using visual studio code and at the time it was working fine. it is a MVC application that uses dotnetcore2.0. When I try to run debugging I get a message "command 'csharp.coreclrAdapterExecutableCommand' not found. I can execute the application by running "dotnet run" from the project folder.
I tried creating a new blank console application that just says "hello world" and again am able to run from "dotnet run" but when I try to debug I get the same message. I am able to run the build task successfully.
I tried to reseaerch the method mentioned in the error but can find little to nothing about it. I believe that omnisharp is the solution that the csharp debug runs in and I looked it up. From their documentation it says that it needs .net framework 4.6 to work. I verified that I have the sdk and runtime for each .net framework installed.
I am usually pretty good at figuring things like this out and this is my very first post on stack. I am hoping that someone might know what the heck this is so that I can move forward.
It would be good to note that I have tried to reboot my machine several times and even uninstalled/reinstalled vs code. An example of the launch.json file is below.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/helloworld/bin/Debug/netcoreapp2.0/helloworld.dll",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"console": "internalConsole"
}
]
}
Thanks to #bman7716 I was able to figure out what was going on. The issue was the omnisharp extension was corrupted (or a related dependency). I was able to resolve the issue by:
Uninstalling the c# extension from VS Code
Close VS Code
remove all C:\Users{username}.vscode\extensions\ms-vscode.csharp-{version}
Open VS Code
Install C# extension
Open Project
Go to Debug mode and start debug
This forced VS Code to re-install omnisharp and its dependencies and things worked just fine afterwards.

No job functions found. Try making your job classes and methods public

First off, I have looked at the other SO posts with the same error message and none seem to resolve my issue. I have tried many permutations and options. My function builds fine but will not run in the CLI, I get the following cryptic error. The MSFT documentation does not seem to have the answers either.
No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
I am trying to run a timer job and then write a collection of messages to an event hub. What am I missing? I have been fighting this for hours.
Function:
[FunctionName("CreateData")]
public static async Task Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
[EventHub("murraytest", Connection = "evingest")] IAsyncCollector<string> myeventhub,
TraceWriter log)
{
await myeventhub.AddAsync("data1");
await myeventhub.AddAsync("data2");
await myeventhub.AddAsync("data3");
log.Info($"COMPLETED: {DateTime.Now}");
}
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"Eventhub": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "",
"evingest": "Endpoint=sb://example.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=LtcqBLT5VWjg0dGMdIvxCcEGs8902010Y6y14iGg="
}
}
Packages
function.json - is missing any eventhub bindings!
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
"configurationSource": "attributes",
"bindings": [
{
"type": "timerTrigger",
"schedule": "0 */5 * * * *",
"useMonitor": true,
"runOnStartup": false,
"name": "myTimer"
}
],
"disabled": false,
"scriptFile": "..\\bin\\AzFuncs.dll",
"entryPoint": "AzFuncs.Function1.Run"
}
If you are using Azure Functions in .NET 5 or higher with the out-of-proces execution model you need to replace your FunctionName with Function, otherwise the function will not be detected.
Before:
[FunctionName("CreateData")]
After:
[Function("CreateData")]
Another gotcha I found especially if you are converting from another project or version.
In the VS csproj file, make sure AzureFunctionsVersion is present
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
...etc
the tooling adds this automatically but not added if you are modifying a project where this was missing. Hope this helps you save the 3 hours it cost me :-).
You should upgrade to the latest Microsoft.NET.Sdk.Functions (1.0.6 as of today) and Microsoft.Azure.WebJobs.Service.Bus (2.1.0-beta4 if running on full framework). You might need to remove the ServiceBus reference first in order to upgrade SDK.
The Microsoft.Azure.Eventhubs package also needs to be removed. All relevant types etc are in Microsoft.Azure.WebJobs.Service.Bus
Also remember to check "Include prerelease" in the package manager in order to find 2.1.0-beta4.
In my case I was simply running the command from an actual function directory. You should run it from the root of the functions project instead!
My issue was different from the other answers: the local.settings.json was explicitly included in the .gitignore definition. As such the file was not included in a clone and the local build couldn't understand which was the correct runtime to use.
I pulled the default local.settings.json from a sample project to restore the file.
I randomly had this issue but it only affected the functions in one class. Turned out I just needed to run a dotnet clean first.
In my case (v3 on net core 3.1) it was a weird case that somehow this was removed from csproj file.
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
In my case, the clue was this message at the start of the console output:
Can't determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell]
Adding the --csharp argument did the trick.
It happened to me when I changed the name of the project and some other refactoring. It was working on that machine after the change, but interesting enough when I switch to a different machine, I got this error - even if it's the same code.
The solution was for me basically creating a random new azure function and running again. All my functions appeared on the cli on the next run.
I was running "func start" from the wrong folder. Make sure you're running it from the root folder of the azure function. This should be true for any language (I'm using python)
I appreciate the other answers here. But in my case none of them worked on VS Code.
I am still trying to use .NET core SDK version of 2.1 and had to use all old version of dependencies for my Azure function.
Even after everything seeming right, I was still unable to run the function locally. Turns out, there is a small step to be taken:
First, publish your project dotnet publish
The published stuff should be in bin/Debug/netstandard2.0 . Just get inside this folder and run your function:
cd bin/Debug/netstandard2.0 # I was using netstandard2.0 framework
func start --build # You can add --verbose flag for more detailed outputs
Voila! That's it. Just to be clear, here are my versions:
.NET core SDK version: 2.1.810
Azure CLI version: 2.12.0
Azure Function version: v2
Microsoft.NET.Sdk.Functions: 1.0.37
I found this error when I use FunctionName like this:
[FunctionName("Example/signup")]
I removed "/" in FunctionName and resolved it.
After having upgraded a lot of packages - amongst others the one that triggered the change from [FunctionName("CreateData")] to [Function("CreateData")], I needed to delete the bin and obj folder before the functions were discovered again.
If it's working from bin/Debug/netcoreapp3.1/ etc this is because you are missing some needed files in the root or missing sections in some files. (eg: host.json)
I managed to fix this by running func init --force to restore the initial setup and use git to find the missing sections.
I got the error
no job functions found
when my firewall was blocking the azure functions program from connecting to the internet.
in my scenario, for Existing Project, I missed to give reference in .csproj file after installing azure function setup in windows
here is it
you can run command on VS Code Func init --force and Select Dotnet template and then delete .csproj file which is created automatically.
local.settings.json
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=false",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
}
.csproj file
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
</ItemGroup>
I hope someone helps out there if you are using like me visual studio code.
For some reason, my working project got this below info duplicated in the csproj file, and so ran into this same error while running the AzFunction locally. I removed the extraneous lines and it worked just fine.
<ItemGroup>
<None Include="Function1.cs" />
</ItemGroup>

Categories