question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BadImageFormatException when using serverless.AspNetCoreWebApp template with Mock Lambda Test Tool

See original GitHub issue

Description

Can’t make request to lambda using Mock Lambda Test Tool when project has reference to Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation Nuget package.

Reproduction Steps

  1. Install templates: dotnet new -i "Amazon.Lambda.Templates::*"

  2. Create new project: dotnet new serverless.AspNetCoreWebApp

  3. Add Nuget reference to Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation

  4. Edit ConfigureServices in startup to enable razor pages to be loaded:

     public void ConfigureServices(IServiceCollection services)
     {
         services.AddControllers();
         var builder = services.AddRazorPages();
         builder.AddRazorRuntimeCompilation();
     }
    
  5. Configure debug configuration for mock test tool as shown in the readme for Rider: Executable and executable path: “<Configured to home directory>\.dotnet\tools\.store\amazon.lambda.testtool-3.1\0.11.4\amazon.lambda.testtool-3.1\0.11.4\tools\netcoreapp3.1\any\Amazon.Lambda.TestTool.BlazorTester.dll”

  6. Create a controller and use attribute routing

  7. Debug application and send in request using Mock Test Tool blazor interface

Request I’m using: { "httpMethod": "GET", "path": "/api/Home" }

Without Nuget reference: image

With Nuget reference: image

Logs

Environment

  • Build Version: Amazon.Lambda.AspNetCoreServer 7.0.1
  • OS Info: Windows 10
  • Build Environment: Jetbrains Rider
  • Targeted .NET Platform: netcoreapp3.1

Resolution

  • Remove reference to Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation (no use for local debugging)

A similar issue also happens when I reference Microsoft.AspNetCore.Mvc.WebApiCompatShim too, but the error is that it can’t find System.Json.


This is a 🐛 bug-report

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
Pankratycommented, May 27, 2022

This issues strikes us as well. We are creating a lambda function for building emails and for that, we are using Razor as a templating engine. Unfortunately, this does not work well with the test tool as we getting the same exception as described in the issue. The fix would be deeply appreciated!

1reaction
ashishdhingracommented, Feb 7, 2022

Thank you for looking into this for me. I appreciate it. I’m trying to get going with the Lambda Test Tool using an existing project, so do you think I’ll just have to remove that reference and it’s functionality in order to use the tool?

@coultonluke Removing that reference resolves the issue. I would have team look at this issue to see if something could be done, before deciding to close the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot start lambda with Mock Lambda Test Tool
I came to this question having the very same issue. After installing AWS Toolkit I found that the lambda test tool was not...
Read more >
Debugging .NET Core AWS Lambda functions using the ...
NET Mock Lambda Test Tool for debugging is to monitor a Lambda ... Here is an example of that assignment in an AWS...
Read more >
MOCK LAMBDA TEST TOOL on JetBrains RIDER - YouTube
When using Visual Studio the default Lambda Function template has everything set up and ready to use with the Lambda test tool.
Read more >
.NET 7 Custom Runtime for AWS Lambda | no dogma blog
What if you want to use a runtime that AWS Lambda functions don't currently support? In this post, I'll show how to get...
Read more >
How to Debug .NET Core Lambda Functions Locally with ...
NET Mock Lambda Test Tool you can now debug your .NET Core Lambda Functions created within the serverless framework — let me show...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found