Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to load type from assembly (C# Amazon lambda function)

Since Amazon now supports C# to build AWS Lambda functions, i wanted to give it a try, but i get stuck when performing a test.

This is my simple class:

using System;
using System.IO;
using System.Text;

using Amazon.Lambda.Core;
//using Amazon.Lambda.Serialization.Json;

namespace MyTest
{
    public static class LambdaFunction
    {
        public static string Handler(Stream stream)
        {
            return "Hello World";
        }
    }
}

I compiled it using the .Net Core runtime. The result is a folder netstandard1.4 with the assembly MyTest.dll file and a MyTest.deps.json file. These compressed as .zip are uploaded to the AWS Lambda console.

In the configuration tab the Handler is defined as:

MyTest::LambdaFunction::Handler

But when i hit the TEST button, this is the error message returned:

{
  "errorType": "LambdaException",
  "errorMessage": "Unable to load type 'LambdaFunction' from assembly 'MyTest, Culture=neutral, PublicKeyToken=null'."
}

Note1 : before i knew i needed to use .Net Core instead of the full CLR, i got an error that the assembly could not be loaded, so i figured the assembly is compiled ok now.

Note2 : I've tried several argument-types (Stream and String are the only supported ones without custom serializer though) for the Handler method, as well as static/instance class or method or any combination, all to no avail.

Anyone who got this working already and can give me a few pointers?

like image 299
Kevin Avatar asked Dec 05 '16 14:12

Kevin


People also ask

Could not load type from assembly version?

This usually happens when you have one version of your assembly deployed in the GAC but has not been updated with new classes that you might have added on the assembly on your IDE. Therefore make sure that the assembly on the GAC is updated with changes you might have made in your project.

Can not load file or assembly?

Http 5.2. 0.0? In summary if you get the "Could not load file or assembly error", this means that either your projects or their references were built with a reference to a specific version of an assembly which is missing from your bin directory or GAC.


1 Answers

Well, it's one of those days i guess....

The answer is, i forgot to include the namespace 8|

Should be:

MyTest::MyTest.LambdaFunction::Handler
like image 117
Kevin Avatar answered Sep 23 '22 02:09

Kevin