Cannot start lambda with Mock Lambda Test Tool - c#

I've been working with AWS lambdas for a few months. I was working with a lambda and it was fine at the end of the day. I came back to work on it the next day, and I can't get Visual Studio to even start the application using the Mock Lambda Test Tool.
I ended up creating an empty lambda that just returns the input (the standard project code that AWS gives you as a template) and that won't even run. I hit the play button to star the Mock Lambda Test Tool, it looks like it will run for a couple seconds, then it closes down. The command window does not even pop up.
This is the code from the template project.
public string FunctionHandler(string input, ILambdaContext context)
{
return input?.ToUpper();
}
This is all I get in the output window of VS:
The target process exited without raising a CoreCLR started event.
Ensure that the target process is configured to use .NET Core. This
may be expected if the target process did not run on .NET Core. The
program '[16700] dotnet-lambda-test-tool-2.1.exe: Program Trace' has
exited with code 0 (0x0). The program '[16700]
dotnet-lambda-test-tool-2.1.exe' has exited with code -2147450726
(0x8000809a).
I have tried re-installing the AWS toolkit, and also tried re-installing Visual Studio. This is an issue with VS 2017 and VS 2019. I just installed 2019 to see if that would fix the issue. Any help would be appreciated.

I came to this question having the very same issue. After installing AWS Toolkit I found that the lambda test tool was not installed and therefore I got the same error just as the OP. The only difference is that I was targeting .Net Core 3.1 and therefore I needed amazon.lambda.testool-3.1. However this answer should work for both scenarios.
Unfortunately I did not have the same luck as the OP of having a nice co-worker that could give me the files I needed. So, if this is also your case please continue reading.
In the official project site, which can be found here, there are the instructions to install the tools. It also says that installing the latest version of AWS Toolkit should be enough to have the tools installed (it was not in my case and probably in yours).
It says that in order to install the tools you should run the following commands:
dotnet tool install -g Amazon.Lambda.TestTool-3.1
or
dotnet tool install -g Amazon.Lambda.TestTool-2.1
depending on which tool you need.
However, running these commands fails with the following message:
The tool package could not be restored.
Tool 'amazon.lambda.testtool-2.1' failed to install. This failure may have been caused by:
* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by this name was found, but it was not a .NET Core tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.
For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool
And since the project is still in preview I just had to find the latest stable version in order to specify it in the command. For .net core 3.1 here is the nuget site, there I found version 0.10 to be the latest, so the command should look like:
dotnet tool install -g --version 0.10 Amazon.Lambda.TestTool-3.1

I have faced the same issue and when i tried to install dotnet-lambda-test-tool-3.1.exe using command prompt I got this issue:
Failed to create shell shim for tool 'amazon.lambda.testtool-3.1': Command 'dotnet-lambda-test-tool-3.1' conflicts with an existing command from another tool.
Tool 'amazon.lambda.testtool-3.1' failed to install.
And I did the following to fix issue
Deleted the dotnet-lamda-test-tool-3.1.exe from the installed folder (C:\Users%USERNAME%.dotnet\tools\dotnet-lambda-test-tool-3.1.exe)
Run dotnet tool install -g --version 0.10 Amazon.Lambda.TestTool-3.1 on cmd.

I have faced the same issue and got errors like "dotnet-lamda-test-tool-2.1.exe has exited with code.."
I did the following to fix the issue
Removed the dotnet-lamda-test-tool-2.1.exe from the installed folder
(C:\Users%USERNAME%.dotnet\tools\dotnet-lambda-test-tool-2.1.exe)
Removed the [amazon.lambda.testtool-2.1] folder as well
(C:\Users%USERNAME%.dotnet\tools\tools.store\amazon.lambda.testtool-2.1)
Installed dotnet tool from Developer command prompt using the command
[install -g Amazon.Lambda.TestTool-2.1]
Run the project. It is working

I have seen this issue many time on my system with dotnet-lambda-test-tool-6.0. Only one fix work for me
Remove dotnet-lambda-test-tool-6.0.exe from C:\Users\username.dotnet\tools
Open Command prompt from C:\Users\username.dotnet\tools
run command dotnet tool install -g Amazon.Lambda.TestTool-6.0

For anyone else that hits this same issue, it had to do with the the AWS toolkit install. I did not modify it, but somehow it was no longer working. I tried un-installing and re-installing, but it was still having issues running it. A co-worker sent me the exe and subdirectory that was setup on his machine under C:\Users\%user%.dotnet\tools. The exe is located in this directory, and there is another folder under .store for amazon.lambda.testtool-2.1. That directory had different folders and files than what I was able to install. So I copied in what he had and it worked. There might be a profile file associated to the tools install that points to these folders and files that might need to be modified. Since I was able to fix it with this, I didnt look any further into that.

I had the same issue with my .NET 6.0 lambda project. I installed the tool by executing dotnet tool install --global Amazon.Lambda.TestTool-6.0 --version 0.12.6 as suggested on https://www.nuget.org/packages/Amazon.Lambda.TestTool-6.0
Just ensure it is installed at %USERPROFILE%\.dotnet\tools\dotnet-lambda-test-tool-6.0.exe

I got the same issue with VS2019 with lambda design in 3.1 version and in Output window getting error
The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
Then checked the folder having multiple version of lambda-test-tool in path
C:\Users{username}.dotnet\tools
I removed all the lambda-test-tool and installed the required tool only with version 3.1 by command in developer command prompt:
dotnet tool install -g --version 0.10 Amazon.Lambda.TestTool-3.1
Then I can able to debug the lambda

Related

Can't locate SDK - VSC

My initial error, in fact, comes from Unity that when I open a script (C#) from it to Visual Studio Code, it opens the code without "auto-completing" my lines of code, which makes learning more difficult.
To solve this problem, I used several tutorials, but none helped. That's why I decided to solve another problem that always appears when I open the Microsoft App, which is "The .NET Core SDK cannot be located: A valid dotnet installation could not be found.".
I installed the dotnet 6.0.44 version on my linux (zorin os 16.2) from commands on the official website and the OS identified it. However, no matter what I do, Visual Studio does not recognize it, not even in the terminal does it find it .
command contradiction
Dotnet version
obs:
Already re-installed SDK
I've had the same error on Zorin OS and other Ubuntu based distributions,
you have to install the SDK by this command:
$ sudo apt-get update && sudo apt-get install -y dotnet-sdk-7.0
If this gives you any errors, read the documentation here.
You can view your installed SDKs by executing
$ dotnet --list-skds

Trying to install MonoGame for mac and VS Code

I'm trying to install MonoGame for mac and VS code. I followed the instructions at https://docs.monogame.net/articles/getting_started/1_setting_up_your_development_environment_macos.html, but I am stuck at one place. I have the monogame editor .mpack file, but can't upload it to VS code for some reason. I did extensive research but can't find any answers. What should I do?
The "normal" Mac install instructions and files are only for use with Visual Studio.
Install using CLI
Please note these instructions are designed for Intel Macs(x64), but should work on Apple Silicon devices(ARM) with .Net6.
You can roughly follow the Linux install instructions.
Install Dot Net Core 3.1 for the Mac. or .Net6
Install VS Code.
You may need to reference this question on Terminal paths for code. Something similar may need to be done below for the dotnet command.
a. Install the C# extensions: code --install-extension ms-dotnettools.csharp
(Optional) Install Mono. Required for some consoles and Android targets(Frameworks 4.5 and 4.7). See here for compatability.
Open a terminal window. Run the following line, either the OS or from VS Code:
dotnet new --install MonoGame.Templates.CSharp
The next two lines may be Linux specific so ignore any uncorrectable errors.
dotnet tool install --global dotnet-mgcb-editor
mgcb-editor --register
At this point, you should be able to create a new CLI project folder from the templates:
cd /path/togame/parent
dotnet new mgdesktopgl -o MyGame
Open the folder in VS Code.
Review the projectname.csproj file:
Note the TargetFramework line:
<TargetFramework>netcoreapp3.1</TargetFramework> or
<TargetFramework>net6.0</TargetFramework>
Some targets require a different TargetFramework, like net47 or net45 as provided by Mono.
See Microsoft's .Net versioning page for more information.
A couple of additional helpful CLI commands to run from the folder with the .proj file; Taken from this list:
dotnet restore Update all NuGet Packages
dotnet clean Remove all output files
dotnet build compile
dotnet run execute the program

Installed Dotnet tools give error "Could not execute because the specified command or file was not found." on Ubuntu WSL2

I'm working on an api in .net core 5 in wsl2 and I followed all the documentation to install the entity framework core tools.
when i run
dotnet tool list -g
it prints
Package Id Version Commands
--------------------------------------
dotnet-ef 5.0.7 dotnet-ef
but when i run
dotnet ef
or any of its child commands, I get this
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET program, but dotnet-ef does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
now, i've looked in my path and it looks like when i ran
dotnet tool install --global dotnet-ef
it installed it under my C drive instead of inside wsl2 which I think might be the problem but I don't understand why running that within ubuntu would install it into my windows directories but this is the line from my path
/mnt/c/Users/ethan/.dotnet/tools
so i guess my question is, is the issue that it unstalled under my windows directories and if so how do i either force it to install on ububtu or change my path and if not what is happening.
i found this post:
Cannot find command 'dotnet ef'
and running
export PATH="$PATH:$HOME/.dotnet/tools/"
makes dotnet ef work until i start a new terminal session so i wanted to double check the right way to make this a permanent fix, according to this article i found https://astrobiomike.github.io/unix/modifying_your_path the best way to handle it is just to add it to your bash_profile or zshrc so thats what i did

Visual Studio Team Services: create build definition for .netcore 1.1

I need to build a package, based on my c# code. I have already created build definition which used to work, but since .netcore 2.0 announcement on VSTS there is default sdk used with version 2.0. Unfortunatelly it is not working well with previous .netcore version.
I am using command line task for each step, just like below:
I am now unable to restore packages, build project or publish it.
Is there a way to specify which dotnet.exe version will be executed during restoring or any other step?
I was trying to specify whole path "$(ProgramFiles)\dotnet\shared\Microsoft.NETCore.App\1.1.2\dotnet.exe" where it is installed even on vsts, I get then:
Furthermore I was trying to setup a powershell step, but I am unable to provide a argument for it.
& "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\1.1.2\dotnet.exe" --version
does not respond with anything. I was trying different way to provide args, but also without any success.
How to run an EXE file in PowerShell with parameters with spaces and quotes
Resolved for now with using dedicated Task component from vsts (nuget resore, visual studio build etc.) instead of command line - dotnet with args like restore/build/etc. Only thing that left for me is run unit tests for this app. Visual Studio test does not find any test in solution even with specified dll name.

Building a .NET Core app via command line, so that it works on a machine without .NET Core installed

My end goal is to create a cross-platform (non-web) console application, so I'm exploring .NET Core right now.
In my previous .NET projects, I did all the development inside Visual Studio, but I also created a batch/MSBuild file so I could build the whole project (including setups, NuGet packages, zip files with binaries etc.) with one single click. Here's an example from a previous project.
In the end, I want to do something similar with my .NET Core test project.
But right now I'm failing at the first step: I'm unable to build it outside Visual Studio, so that the result works on another Windows machine without .NET Core installed.
(in the first step, I'm ignoring the cross-platform part - I'll be happy to get it to work on Windows)
What I have
I managed to get it to work inside Visual Studio 2015 Community Edition as follows:
create new project in Visual Studio: "New Project" ⇒ "Web" ⇒ "Console Application (Package)"
create new publish profile inside Visual Studio ("Build" ⇒ "Publish" in the menu).
This will create a PowerShell script (and an XML file with settings)
Here's my test project on GitHub.
When I do "Build" ⇒ "Publish" in the menu again, Visual Studio apparently executes the previously created PowerShell script again.
The result is slightly over 90 MB, consists of 825 files in 598 folders, and looks like this:
When I copy it on another machine (Win 7 / .NET 4 installed / .NET Core not installed), it works.
What I tried to get the same result outside Visual Studio
1. dotnet publish
This answer and this answer sound like I can use dnu publish to achieve the same result via the command line.
I understand that parts of .NET Core are still moving targets right now, so apparently dnu is now dotnet instead.
So I tried to execute dotnet publish (and created a batch file) for it:
dotnet publish "%~dp0\src\CoreTestVisualStudio" -c Release -r win7-x64 -o "%~dp0\release\cli"
The result consists of an .exe file and a bunch of DLLs, only 25 files and 1.5 MB, all in one single folder:
Obviously the .NET Core runtime is missing here, and as expected, this app crashes when I try to execute it on a machine without .NET Core installed (the same one as mentioned above).
2. The PowerShell script from the publish profile
I tried to execute the PowerShell script (which was created when I created the publish profile) outside Visual Studio, but it failed because the script expects some parameters and I don't know what to pass:
param($publishProperties, $packOutput, $nugetUrl)
There's also this line in the script:
# to learn more about this file visit http://go.microsoft.com/fwlink/?LinkId=524327
...but the link just points to the landing page of the .NET Web Development and Tools Blog.
TL;DR
What am I doing wrong?
I know that the first release of .NET Core mainly focuses on ASP.NET, but as I understood it, ASP.NET Core apps are just console apps as well, so I thought a basic console app would work now.
On the other hand, most of the console app "getting started" docs are still missing, so maybe it's just too early and dotnet publish for console apps is not finished yet?
Edit after a few days: I'm suspecting that I'm doing nothing wrong and that it's an issue in the.NET Core command line tools, so I posted it to the command line tools' issue tracker.
Problem solved!
I posted it on the issue tracker of the .NET Core command line tools, and it turned out that it was a bug in dotnet publish - it didn't bundle the C++ runtime, which is needed to execute the compiled app on a machine without .NET Core installed.
The temporary solution was to install the C++ runtime.
The "real" solution was made in a pull request three days ago, which is included in the latest installer now.
With this version, dotnet publish does bundle the C++ runtime, so the result will work on a machine without .NET Core.
For dnu:
There's an option for dnu publish called --runtime that specifies the runtime to include when publishing. You would use the full runtime name with the command, e.g.:
dnu publish --runtime dnx-clr-win-x86.1.0.0-rc1
For dotnet:
You don't need to specify the runtime or framework versions -- by default, dotnet publish will use the framework from project.json and the current runtime flavor. However, the documentation states that:
dotnet-publish command also requires certain dependencies in the project.json to work. Namely the Microsoft.NETCore.Runtime package must be referenced as a dependency in order for the command to copy the runtime files as well as the application's files to the published location.

Categories

Resources