Dotnet Lambda Test Tool Blazor UI does not support changes Lambda Project RootNamespace - FileNotFoundException: Could not load file or assembly
Describe the bug
Using the standard dotnet template for the "Lambda Annotations Framework (preview)" and editing the .csproj to add a `<RootNamespace>OtherNamespace</RootNamespace> element:
<PropertyGroup>
<OutputType>Library</OutputType>
<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 improvement cold starts. -->
<PublishReadyToRun>true</PublishReadyToRun>
<RootNamespace>Other</RootNamespace>
</PropertyGroup>
results in the following exception:

Expected Behavior
The Blazer test harness should pick up the assembly information for each Function from the serverless.tempate as configured in the aws-lambda-tools-defaults.json and establish the assembly name for the "Handler" element of each Function, based on <assembly name>::<fully qualified class name>::<function method name>
Current Behavior
If the template project is left as is the Lambda Test tool works as expected and appears to pick up the assembly information from the serverless.tempate as configured in the aws-lambda-tools-defaults.json.
However if the .cspoj is augmented with a RootNamespace element as above in the Bug Description it fails.
Reproduction Steps
- create a solution from the default template of the "Lambda Annotations Framework (preview)" template
- build solution and observe the generated
"Hander"element for each function in theserverless.template - configure the dotnet Lambda Test - Blazor setup
- verify the setup is good by launching the debugger - browser window open with test harness successfully
- add alternate
<RootNamesapce>element into thecsproj, and adjust namespace in theFunctions.csaccordingly - rebuild solution and observe the generated
"Hander"element for each function in theserverless.template - relaunch the debugger to get the above exception.
Possible Solution
One suspects that the code is not actually using the serverless.template or if it is, decoding the "Handler" string correctly.
Update: On inspection of the source, even though the code parses the serverless.template to find all the handlers, it does not use the handler to determine the assembly, instead it looks for the *.deps.json fie on the build folder, and truncates that extension and add the .dll - see lines 56-69 of LocalLambdaRuntime.cs
Additional Information/Context
No response
AWS .NET SDK and/or Package version used
Amazon.Lambda.Core 2.1.0 Amazon.Lambda.APIGatewayEvents 2.4.1 Amazon.Lambda.Serialization.SystemTextJson 2.3.0 Amazon.Lambda.Annotations" 0.5.0-preview
Targeted .NET Platform
.NET 6
Operating System and version
OSX Monterey
@Simonl9l Thanks for reporting the issue. It is reproducible.
The root cause is that per updated serverless.template, the handler is set as Other::Other.Functions_Divide_Generated::Divide. So it is looking for assembly named Other. However, by default, assembly name in project settings is set to $(MSBuildProjectName). Hence the compiled assembly is named as LambdaAnnotationsRootNamespace_Issue1249.dll (for example). This needs review with the team, may be it is a simple fix to set assembly name in serverless.template properly.
Workaround could be to set the assembly name to value set in RootNamespace. But this might not be scalable solution.
@ashishdhingra thanks for looking, please advise on future updates or if you need any additional information.
@ashishdhingra thanks for looking, please advise on future updates or if you need any additional information.
@Simonl9l Good morning. Could you please try upgrading to latest version of Amazon.Lambda.Annotations (currently 0.13.3) and see if the issue is resolved? I tried the latest version while investigating the changes; the Handler attribute in the generated serverless.template is now correctly set as "Handler": "LambdaAnnotationsRootNamespace_Issue1249::Other.Functions_Add_Generated::Add" (for example) and Lambda Test Tool is now successfully launched.
Thanks, Ashish
@ashishdhingra will have a look and get back to you
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.