Skip to content

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

@coultonluke

Description

@coultonluke

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: "\.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

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.module/lambda-test-toolp2This is a standard priority issuequeuedresponse-requestedWaiting on additional info and feedback. Will move to close soon in 7 days.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions