Debug C# NativeAOT Lambda Function - c#

I created a .NET 7.0 NativeAOT Lambda function from the AWS Templates. I haven't changed it. I installed the Mock Lambda Test Tool. I believe I have to use the Executable Assembly page to test my function? I can't figure out how to test it though. Do I need to set up docker and sam to test it locally? Or do I just build my C# and run the tool? It's just supposed to take a string and convert it to upper case. I haven't been able to find a tutorial on how to do this...
I tried running the Mock Lambda Test Tool 7.0. I was expecting to send my function a string and it return an uppercase string.
I'm running VS Code on Linux. Here's my launch.json:
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
//"program": "${workspaceFolder}/DocGenerator/bin/Debug/net7.0/linux-x64/bootstrap.dll",
"program": "${env:HOME}/.dotnet/tools/dotnet-lambda-test-tool-7.0",
"args": ["--port 5050"],
"cwd": "${workspaceFolder}/DocGenerator",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
This is my aws-lambda-tools-default.json:
{
"Information": [
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",
"dotnet lambda help",
"All the command line options for the Lambda command can be specified in this file."
],
"profile": "default",
"region": "us-east-1",
"configuration": "Release",
"function-runtime": "provided.al2",
"function-memory-size": 256,
"function-timeout": 30,
"function-handler": "bootstrap",
"msbuild-parameters": "--self-contained true"
}

Please check the "launchSettings.json" file under properties folder
change the "executablePath" Path and "workingDirectory" and try to run and debug the code,
it should work. code here
"executablePath": "%USERPROFILE%\.dotnet\tools\dotnet-lambda-test-tool-7.0.exe",
"commandLineArgs": "--port 5050",
"workingDirectory": ".\bin\$(Configuration)\net7.0",

Related

Why is my program not debugging on vscode (c#) like it used to? I am being asked to attach to a process

[Disclaimer: very new to coding]
I am learning to code and have so far covered some basic tutorials and can produce simple programs. These all used to run fine.
For some reason I can't explain, I am now running into an error every time I am trying to "start debugging".
For example, when trying to debug the default "Hello World!" code (as below),
using System;
namespace specialitySelector
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
A drop down list appears (as below) and the program does not run! I have no idea why this is doing this :/.
Image of drop down list that appears and what I see
In my launch.json file I have this:
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net5.0/specialitySelector.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "externalTerminal",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
What am I doing wrong and how do I fix this? I have even tried uninstalling and re-installing vscode with no result.
Thanks.

VS Code debugger cannot "step" for .NET Console App

I'm using VS code to write a simple .NET console application. Here's a look at my app's entry point:
Program.cs:
using System;
namespace MyApp
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("test");
Console.WriteLine("another test");
}
}
}
I set a breakpoint on the line that reads, Console.WriteLine("test"), and start VS Code's debugger. The debugger highlights the line I've selected once it reaches that point in execution. Great. Then I press the "step over" button.
Expected behavior: test will be written to the debug console and the debugger will advance to the next line of code.
Actual behavior: test is not written to the debug console. Execution stops immediately and the console reads: The program '[3803] MyApp.dll' has exited with code 0 (0x0).
I re-launch my simple application without changing anything. The debugger once again stops at Console.WriteLine("test"). This time I press F5 to continue running. Again, nothing is written to the console and I am shown that the app has exited with code 0.
I re-launch the app, again. When the debugger stops at Console.WriteLine("test"), I un-set my breakpoint and press F5. test is written to the console, followed by another test, and the application finishes (with code 0, of course). I've found that the debugger will break at a later breakpoint, but I must un-set each breakpoint as it is reached (and then continue running / press F5)... otherwise the application stops running and I'm shown the same, simple exited with code 0 message. Un-setting a breakpoint makes no difference for "stepping over" / "stepping into" - those commands do not seem to work at all.
For what it's worth, I'm working on a MacBook running macOS Big Sur on an Apple M1 chip (I have no idea if this is useful information). Here is more detailed information about my workspace configuration:
MyApp.soln:
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.808.8
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyApp", "MyApp\MyApp.csproj", "{D12824DE-83AF-4C7B-B5C2-C6CB1B9554C6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|anycpu = Debug|anycpu
Release|anycpu = Release|anycpu
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D12824DE-83AF-4C7B-B5C2-C6CB1B9554C6}.Debug|anycpu.ActiveCfg = Debug|anycpu
{D12824DE-83AF-4C7B-B5C2-C6CB1B9554C6}.Debug|anycpu.Build.0 = Debug|anycpu
{D12824DE-83AF-4C7B-B5C2-C6CB1B9554C6}.Release|anycpu.ActiveCfg = Release|anycpu
{D12824DE-83AF-4C7B-B5C2-C6CB1B9554C6}.Release|anycpu.Build.0 = Release|anycpu
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8A94F55D-F55A-450C-A412-10554B4B7799}
EndGlobalSection
EndGlobal
MyApp.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/MyApp/bin/Debug/net5.0/MyApp.dll",
"args": [],
"cwd": "${workspaceFolder}/MyApp/bin/Debug/net5.0",
"stopAtEntry": false,
"console": "internalConsole"
}
]
}
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/MyApp/MyApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/MyApp/MyApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/MyApp/MyApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
How can I get VS Code's debugger to work as expected?
I believe that the .NET 5.0 SDK is not fully compatible with the new Apple M1 chip. I followed the process below on two Macs: one with an Intel chip and the other with an M1 chip:
Install the .NET 5.0 SDK.
Run dotnet new console to create a new console application.
Create a file, .vscode/launch.json, open it, and click the "Add Configuration" button. Select .NET: Launch .NET Core Console App. Update all placeholder-text in the file according to the structure of your project. You'll also need to create a .vscode/tasks.json file like the one that I included in my original post.
Attempt to debug the project in VS Code.
Running and debugging the application with this launch configuration works as expected on my Intel-chip-Mac, but not on my M1-chip-Mac. Looks like I'll be working from my old Mac until an M1-compatible .NET SDK is released.

C#: Visual studio code compile time

I have a C# (.net core v2.1) solution that built from some of projects. Compile it takes ~90 seconds. This is my tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [ "${workspaceFolder}\\my.sln"],
"isBuildCommand": true,
"showOutput": "silent",
"problemMatcher": "$msCompile"
}
]
}
This is my lunch.json:
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": "Test",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/Tests/Test/bin/Debug/netcoreapp2.1/Test.dll",
"args": [],
"cwd": "${workspaceFolder}/Tests/Test/",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
]
}
I notice that every time I build the project OR run the current configuration - it compile all the project agian - agian, 90 seconds of waiting.
In previous days, I did it with Visual Studio (the old and good) much more faster - it wasn't compile all the projects UNLESS they changed.
Is this possible to do it with Visual Studio Code?

Visual Studio Code: How to configure 'dotnet' not to show warnings when compiling

OK. I am in .NET Core and using Visual Studio Code on a Mac machine. Now, whenever I run my C# project then Visual Studio Code shows this annoying message:
The preLaunch task 'build' terminated with exit code 1
It shows me the option to click on a button called "Show problems". When I click on this button, it only shows the warning messages.
Now, if it was errors then it's OK to see this message. But the fact that it shows this message every time there are warnings (which to me is OK). That is very annoying. Is there a way I can configure Visual Studio Code to not show these messages on things like warnings?
In order to disable warnings, you should add -nowarn to args in the tasks.json file:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/MyProject.csproj",
"-nowarn" // here
],
"problemMatcher": "$msCompile"
}
]
}
It might be a problem with your task.json file. Check the arguments of the file and make sure the build is pointing at the right location:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/MyProject.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

ASP.NET core web API json configuration not copied to debug folder

I am working on an ASPNET core web API application. When I try to debug the application, the "appsetting.json" file is not copied to the debug folder. At this moment I am copying this file whenever I made changes. If I did not copy the file and I just run the dotnet run command, the application fails to load giving the file not found exception.
Should I do anything in the Launch.json file?
Here is what I have in mine.
I have also tried adding
"/appsettings.json":"${workspaceFolder}/appsettings.json"
in the "sourceFileMap" property in this JSON file but no use.
Please help.
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "attach",
"name": "Attach to Chrome",
"port": 9222,
"webRoot": "${workspaceFolder}"
},
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/SmartAPI/bin/Debug/netcoreapp2.0/smartAPI.dll",
"args": [
],
"cwd": "${workspaceFolder}/SmartAPI",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"requireExactSource": false,
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
}
]
}
Right click on the file in object explorer, click on properties and change the value of "Copy to output directory". This is do not copy by default when you create the project but can be changed.
Update
Didn't realise you were using VS Code - this answer might help you: https://stackoverflow.com/a/44378406/8532748

Categories

Resources