aws-lambda-dotnet icon indicating copy to clipboard operation
aws-lambda-dotnet copied to clipboard

Dotnet Lambda Test Tool Blazor UI does not support changes Lambda Project RootNamespace - FileNotFoundException: Could not load file or assembly

Open Simonl9l opened this issue 3 years ago • 2 comments

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: Screen Shot 2022-07-19 at 4 27 09 PM

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

  1. create a solution from the default template of the "Lambda Annotations Framework (preview)" template
  2. build solution and observe the generated "Hander" element for each function in the serverless.template
  3. configure the dotnet Lambda Test - Blazor setup
  4. verify the setup is good by launching the debugger - browser window open with test harness successfully
  5. add alternate <RootNamesapce> element into the csproj, and adjust namespace in the Functions.cs accordingly
  6. rebuild solution and observe the generated "Hander" element for each function in the serverless.template
  7. 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 avatar Jul 19 '22 23:07 Simonl9l

@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 avatar Aug 10 '22 18:08 ashishdhingra

@ashishdhingra thanks for looking, please advise on future updates or if you need any additional information.

Simonl9l avatar Aug 14 '22 17:08 Simonl9l

@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 avatar Jun 08 '23 17:06 ashishdhingra

@ashishdhingra will have a look and get back to you

Simonl9l avatar Jun 13 '23 00:06 Simonl9l

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.

github-actions[bot] avatar Jun 19 '23 00:06 github-actions[bot]