Error Deploying Asp.Net Minimal API (Top level statements) to lambda using CDK - asp.net

I have a CDK solution with a stack etc and in the same solution i have created a ASP.NET minimal API Lambda project.
When I deploy using the CDK I'm getting the ERROR:
Internal Server Error
When I check the logs I can see the Error:
Error: executable assembly /var/task/lambdaMinimalApi.dll was not found..
I know what this error is, it is trying to find the Lambda function thinking its a libary, but mine is an executable. I know this as when i deploy the lambda with:
dotnet lambda deploy-function
through trial an error i found out this:
.NET Lambda projects that use C# top level statements like this project must be deployed as an executable assembly instead of a class library. To indicate to Lambda that the .NET function is an executable assembly the Lambda function handler value is set to the .NET Assembly name. This is different then deploying as a class library where the function handler string includes the assembly, type and method name.
Following this and just using the assembly name I can deploy and everything works.
But when it comes to the CDK I get the internal server error mentioned above.
My public repo is here: https://github.com/RollsChris/cdk-twitter-clone-dotnet
I think it will be a good example to add to the official examples if I can get it to work?
I have tried various forms of Code.From**, and searched the internet far and wide.
Most examples are using a lambda function written in javascript but the CDK is using .NET.
Thanks

Looking at your repo and the error message in the question...
Error: executable assembly /var/task/lambdaMinimalApi.dll was not
found.
Could it be the project is outputing a DLL called lambdaMinimalAPI but your code is specifying different casing (pascal casing API at the end)
var lambdaFunction = new Function(this, "lambdaMinimalAPI", new FunctionProps
{
Runtime = Runtime.DOTNET_6,
Code = Code.FromAsset("src/lambdaMinimalApi",assetOptions),
Handler = "lambdaMinimalApi",
Environment = new Dictionary<string, string>
{
["userProfilesTable"] = userProfilesTable.TableName,
["tweetsTable"] = tweetsTable.TableName,
},
MemorySize = 256,
Timeout = Duration.Seconds(30),
Architecture = Architecture.X86_64
});
Hanlder should be like so:
Handler = "lambdaMinimalAPI", // UPPERCASE API

Related

Correctly call matlab dll from asp.net webform

Recently I've been starting with Asp.net, particularly Web Form application. And in the application, I need to reference a dll produced by Matlab deploytool (including a .m function I wrote myself).
I copied all relevant dlls to the Bin directory, add reference in the application and using the corresponding namespace. The compiler works fine but a TypeInitializationException was thrown in runtime when trying to initialize an instance of my matlab class.
BTW, in a Windows Form application it works fine amazingly, but not in Web Form applcation. Is there anything I missed when calling a matlab dll? e.g. Add XML comment in Web.config ?
Here is the key code from where the exception was thrown:
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
using diseases; //this is the namespace of urinary_bladder created by deploytool
...
MWArray [] value = new MWArray[8]; // This statement works well
urinary_bladder ub = new urinary_bladder(); // A 'TypeInitializationException' was thrown here
I'll appreciate any of your replies, thx a lot.

Error when using source of Servicestack instead of dll

I'm trying to use the source of the ServiceStack framework to get a real grasp of how the authentication works instead of following the source code.
I started by cloning the master rep of ServiceStack and adding the csproj of ServiceInterface to my solution. I then removed the ServiceStack.ServiceInterface dll and added the local project. Due to dependencies I added also to my solution the projects: ServiceStack, ServiceStack.Common, ServiceStack.Interfaces, ServiceStack.OrmLite and ServiceStack.OrmLite.
If I add the plugin AuthFeature I get the following error:
System.MissingMethodException: Method not found: 'Void ServiceStack.ServiceInterface.AuthFeature..ctor(System.Func`1<ServiceStack.ServiceInterface.Auth.IAuthSession>, ServiceStack.ServiceInterface.Auth.IAuthProvider[])'.
I think that the reflection method cannot find the constructor of the class, but the class in the source has the constructor public AuthFeature(Func<IAuthSession> sessionFactory, IAuthProvider[] authProviders, string htmlRedirect = "~/login") that I believe it matches the signature of the missing method error.
The version of the working dll version is 3.9.43 from Nuget.
I can provide more details if needed.

Mock object injected via AutoFixture with AutoMoq, unexpected behavior

I've just created my first test using AutoFixture. The SUT has the following constructor.
public LoggingService(
IClientDataProvider clientDataProvider, ... other dependencies...)
The test setup has the following code.
var fixture = new Fixture().Customize(new AutoMoqCustomization());
string ipAddress = "whatever";// fixture.CreateAnonymous<string>();
var clientDataProviderMock = fixture.Freeze<Mock<IClientDataProvider>>();
clientDataProviderMock.Setup(cdp => cdp.IpAddress).Returns(ipAddress);
LoggingService sut = fixture.CreateAnonymous<LoggingService>();
Now, when I examine the contents of sut, I see that the property IpAddress of the injected instance of IClientDataProvider returns null instead of "whatever".
What did I do wrong?
I copied the service and the necessary interfaces to an empty project and then the mocks worked as expected.
Interfaces that are types of constructor arguments of the service in the real project are defined in 3 separate assemblies that have further dependencies. I had several unexpected "Cannot load assembly" errors on the test start because several further assemblies were needed for those directly referenced assemblies. So it seems to be an assembly loading issue.
However, I tried a variation of the test with manual creation of the SUT instance with mock objects created manually using Moq and the test worked as expected
The solution was pretty surprising. When I was creating my unit test project I added the reference to Moq 4.0 first. AutoFixture was added later and since it seems to require Moq 3.1, I copied that dll directly to bin\Debug. However, the corresponding HintPath element in the project file still pointed to the 4.0 dll. As soon as I changed HintPath to point to the place where Moq 3.1 sits the test started to work properly. So Mark was right with his suggestion but the symptoms were quite different.

asp.net web service, Error Generating XML Document

I've created an asp.net web service and am trying to test it using my client. The web method I'm currently testing returns a custom object named GetAllTicketsSinceLastPullDateResult, which contains one ArrayList of custom clsTrip objects, and a custom object called FaultResponse. This is how I'm using my client:
ServiceReference1.ServiceSoapClient myClient = new ServiceReference1.ServiceSoapClient();
ServiceReference1.GetAllTicketsSinceLastPullDateResult result = new ServiceReference1.GetAllTicketsSinceLastPullDateResult();
result = myClient.getAllTicketsSinceLastPullDate(myUser);
But I get the following error:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type clsTicket was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
I Google the error and most of the answers I find have to do with serializing derived classes. But my clsTicket class is not a derived class. What can be causing this error? How do I use XmlInclude or SoapInclude?
Thanks in advance!
Okay I finally got it to work, I ended up putting the following line:
[XmlInclude(typeof(clsTicket))]
Between [WebMethod] and my method's definition. So far so good.
I don't think you need to 'new' result:
ServiceReference1.GetAllTicketsSinceLastPullDateResult result;
result = myClient.getAllTicketsSinceLastPullDate(myUser);
Also, how do you know the error isn't on the server?
Can you call the function with a web browser?
Have you updated your service since initially adding the reference to your project? If you're using Visual Studio's "Add Web Reference" feature and you update the service, often times there is a configuration or parameter chance, which can generate SOAP errors.
Try right clicking on the Web Service in question through visual studio and select "Update" option. Recompile the app and see if that resolves your issue.

Using the AspNetCompiler class

I am trying to precompile an ASP.NET web site (not web application project) using the AspNetCompiler class, so that I don't have to run the aspnet_compiler.exe command directly.
The MSDN reference is here: http://msdn.microsoft.com/en-us/library/ms124552.aspx
Has anyone gotten this to work?
The code I'm trying to run is:
AspNetCompiler anc = new AspNetCompiler();
anc.PhysicalPath = physicalPath;
anc.TargetPath = targetPath;
anc.VirtualPath = "/";
anc.Execute();
It errors with this:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Build.Utilities.TaskLoggingHelper.LogExternalProjectStarted(String message, String helpKeyword, String projectFile, String targetNames)
at Microsoft.Build.Tasks.AspNetCompiler.Execute()
If you need a tool, http://www.west-wind.com/tools/aspnetcompiler.asp from Rick Strahl is one I use if needed. I don't believe he used the class, only a GUI wrapper for the cmd line.
Don't need to call it programmatically. You should use it as a build task. Take a look at
http://blogs.msdn.com/b/webdevtools/archive/2010/05/14/the-aspnet-compiler-build-task-in-visual-studio-2010-asp-net-mvc-2-projects.aspx
http://eliasbland.wordpress.com/2010/08/18/compile-aspx-pages-at-compile-time-using-the-aspnetcompiler-build-task/

Resources