lambci / docker-lambda

Docker images and test runners that replicate the live AWS Lambda environment
MIT License
5.83k stars 431 forks source link

dotnetcore2.1 code runs on AWS but not on local #154

Open MarkFl12 opened 5 years ago

MarkFl12 commented 5 years ago

I have an issue trying to use the RazorLight package on docker-lambda. It errors with "Can't load metadata reference from the entry assembly. Make sure PreserveCompilationContext is set to true in *.csproj file" but only when run on docker-lambda. It runs properly when run on live AWS.

I've boiled it down to a minimal reproduction case here:

LambdaTest.zip

It's running on dotnetcore2.1 and originally it was running through the aws-sam-cli but running it via docker run --rm -v ${PWD}/bin/release/netcoreapp2.1/publish:/var/task lambci/lambda:dotnetcore2.1 LambdaTest::LambdaTest.Function::FunctionHandler '"""someevent"""' in powershell also causes the issue.

Running Docker Desktop 2.0.0.0-win81 (29211) with engine 18.09.0.

mhart commented 5 years ago

I'm not aware enough of dotnetcore2.1 to know what might be going on here – the only thing that springs to mind is that it might be a similar issue to https://github.com/lambci/docker-lambda/issues/109 – but I'm not sure what the fix is

recumbent commented 5 years ago

Looking at this my guess would be that the problem is that the LambdaTest.deps.json file (created by PreserveCompilationContext) can't be found by the executing code and that in turn is what is causing the code to throw the error.

To amplify this a bit, the executing application in this case is in a different folder to the assemblies for the lambda function, this in turn means that any file that is assumed to be in the same location as (or a known location relative to) the exe will fail. So in my case it was that the configuration file was in the wrong place, in this case it would be the deps.json that's not being found.

As of yet I haven't had an opportunity to see if there's a straightforward way to address this problem as the environment based fix I have is sufficient to meet my current needs (but probably won't be sufficient to make this work).