Unable to get the LambdaTestTool to find the assembly that needs to be debugged when using multiple projects.
Describe the bug
Unable to get the LambdaTestTool to find the assembly that needs to be debugged
Expected Behavior
Debugging starts in the correct assembly
Current Behavior
It always errors that it cannot load the assembly
Reproduction Steps
Have a solution with multiple projects, for example
- Project.Api
- Project.Lambda And Project.Lambda has a dependency on Project.Api.
When compiling, the bin\debug\net6 directory for Project.Lambda contains a Project.Api.deps.json AND a Project.Lambda.deps.json. The tools picks up the Project.Api.deps.json (FirstOrDefault) and can therefor never find the Project.Lambda.dll assembly
Possible Solution
No response
Additional Information/Context
Workaround is to delete the not required *.deps.json files from the directory before running the tool.
AWS .NET SDK and/or Package version used
AWSSDK.Lambda 3.7.13.18
Targeted .NET Platform
NET6
Operating System and version
Window 10
Hi @geedsen,
Good morning.
Thanks for reporting the issue. Could you please share the sample code solution for reproduction? Also request you to add proper issue title for easy tracking. :blush:
Thanks, Ashish
Sorry, I dont have a sample, Just production code. Could you not reproduce it?
Get Outlook for Androidhttps://aka.ms/AAb9ysg
From: Ashish Dhingra @.> Sent: Friday, July 8, 2022 6:02:26 PM To: aws/aws-lambda-dotnet @.> Cc: Ben Geerdes @.>; Mention @.> Subject: Re: [aws/aws-lambda-dotnet] (short issue description) (Issue #1235)
Hi @geedsenhttps://github.com/geedsen,
Good morning.
Thanks for reporting the issue. Could you please share the sample code solution for reproduction? Also request you to add proper issue title for easy tracking. 😊
Thanks, Ashish
— Reply to this email directly, view it on GitHubhttps://github.com/aws/aws-lambda-dotnet/issues/1235#issuecomment-1179148595, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAKBN42R4OB3E2AGSF5TNALVTBGJFANCNFSM53AMY6FQ. You are receiving this because you were mentioned.Message ID: @.***>
@geedsen Somehow, I'm unable to reproduce the issue. Used Visual Studio 2022 and Empty Lambda Function project template to create the Lambda project, and added Project.Api class library project. Used AWS .NET Core 6.0 Mock Lambda Test Tool (0.12.3) for debugging.
Project.Api.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
Project.Api.Operations
namespace Project.Api
{
public class Operations
{
public static int Add(int x, int y) => x + y;
}
}
Project.Lambda.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
<!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. -->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<!-- Generate ready to run images during publishing to improve cold start time. -->
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Project.Api\Project.Api.csproj" />
</ItemGroup>
</Project>
Project.Lambda.Function
using Amazon.Lambda.Core;
using Project.Api;
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
namespace Project.Lambda;
public class Function
{
/// <summary>
/// A simple function that takes a string and does a ToUpper
/// </summary>
/// <param name="input"></param>
/// <param name="context"></param>
/// <returns></returns>
public string FunctionHandler(string input, ILambdaContext context)
{
return input.ToUpper() + Operations.Add(1, 2);
}
}
aws-lambda-tools.defaults.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-2",
"configuration": "Release",
"function-runtime": "dotnet6",
"function-memory-size": 256,
"function-timeout": 30,
"function-handler": "Project.Lambda::Project.Lambda.Function::FunctionHandler"
}
Output:

Thanks, Ashish
Is there anyway I can provide more details without geving the code? I can provide details with screenshots. All the csproj files. In my case when I build the project the lambda bin directory ends up with four different .deps.json files. So under what condition are they created and copied to the destination directory? I'm sure you see in the testtool code that it picks up the firstordefault, so you must realise that this could pick up the wrong file if there are more than one in the destination directory. If I find some time I will try to reproduce it Cheers Ben
Get Outlook for Androidhttps://aka.ms/AAb9ysg
From: Ashish Dhingra @.> Sent: Tuesday, July 12, 2022 1:15:43 AM To: aws/aws-lambda-dotnet @.> Cc: Ben Geerdes @.>; Mention @.> Subject: Re: [aws/aws-lambda-dotnet] Unable to get the LambdaTestTool to find the assembly that needs to be debugged when using multiple projects. (Issue #1235)
@geedsenhttps://github.com/geedsen Somehow, I'm unable to reproduce the issue. Used Visual Studio 2022 and Empty Lambda Function project template to create the Lambda project, and added Project.Api class library project. Used AWS .NET Core 6.0 Mock Lambda Test Tool (0.12.3) for debugging. Project.Api.csproj
Project.Api.Operations
namespace Project.Api { public class Operations { public static int Add(int x, int y) => x + y; } }
Project.Lambda.csproj
Project.Lambda.Function
using Amazon.Lambda.Core; using Project.Api;
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class. [assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
namespace Project.Lambda;
public class Function {
/// <summary>
/// A simple function that takes a string and does a ToUpper
/// </summary>
/// <param name="input"></param>
/// <param name="context"></param>
/// <returns></returns>
public string FunctionHandler(string input, ILambdaContext context)
{
return input.ToUpper() + Operations.Add(1, 2);
}
}
aws-lambda-tools.defaults.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-2", "configuration": "Release", "function-runtime": "dotnet6", "function-memory-size": 256, "function-timeout": 30, "function-handler": "Project.Lambda::Project.Lambda.Function::FunctionHandler" }
Output: [Screen Shot 2022-07-11 at 4 14 24 PM]https://user-images.githubusercontent.com/67916761/178374173-35cd2ea7-7255-4cd2-88b1-305149333431.png
Thanks, Ashish
— Reply to this email directly, view it on GitHubhttps://github.com/aws/aws-lambda-dotnet/issues/1235#issuecomment-1181045785, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAKBN4ZWSOH54N3JFFRWLOTVTSTJ7ANCNFSM53AMY6FQ. You are receiving this because you were mentioned.Message ID: @.***>
This issue has not received a response in 5 days. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.
I was able to reproduce the problem. I'm assuming @geedsen that Project.Api is an executable project which is causing multiple deps.json files to be written.
The test tool should prioritize the deps.json file that matches the name of the assembly specified in the function handler string.
Edit: After looking at the code we load the deps.json file before the user provides the function handler string. This is required to setup the AssemblyLoadContext. I'll have to do some more investigating on how we can figure out the name of the assembly being debugged which might involve searching for the project file.
@normj sees this is also related to https://github.com/aws/aws-lambda-dotnet/issues/1249 - in that the assembly for each handler is know from the "Hander" in the serverless.template as stored as part of the LambdaFunctionInfo.
Is it also correct per https://github.com/aws/aws-lambda-dotnet/issues/1247 that currently the test tool is not calling any Init (lifecycle) behavior based on what is generated behind the Amazon.Lambda.Annotations.LambdaStartup attribute?
Are there also any plans to support extensions?
+1 Experiencing the same problem.
[...] bin directory ends up with four different .deps.json files. So under what condition are they created and copied to the destination directory?
FWIW, this seems to be an issue with .NET tooling rather than aws-lambda-dotnet tooling. If you run good ol' dotnet publish in the downstream .Lambda project, it creates two *.deps.json files in the bin directory - No lambda tooling is involved in this AIUI.
Moreover, this only happens with .NET SDK 6.0.x; I have a project that produces 1 .deps file with sdk 3.1.x and 2 .deps files with sdk 6.0.x with no changes to the project itself.
Oh man, this was my issue too. Thank you @normj for your investigation! I see this was merged; what is the timeline for this fix to get released?
@rickdgray-dc We have a couple more PRs that are almost done and then we will make a release with all of the changes.
Version 0.14.0 of the tool has been released with the fix.
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.