Error when using source of Servicestack instead of dll - reflection

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.

Related

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

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

What does it mean that Microsoft.NETCore.Runtime.CoreCLR package is not installed in a .NET core project?

I'm trying to get my head around the low level of .NET core to understand what is going on,
I know that CoreCLR provide the garbage collector, JIT compiler, base .NET types, and other low-level classes, which eventually imply that it is part of any running application.
When I looked for it in an ASP.NET Core project, I found it's not installed, moreover, it's available for download as a NuGet package.
Then I found this interesting part in the README file of the CoreCLR repository:
But the main reason you can't do much with CoreCLR is that ALL of the types in the class library LOOK like they are defined by the CoreFX framework and not CoreCLR. Any library code defined here lives in a single DLL called System.Private.CoreLib.dll and as its name suggests is private (hidden). Instead for any particular PUBLIC type defined in CoreCLR, we found the 'right' package in CoreFX where it naturally belongs and use that package as its public publishing point. That 'facade' package then forwards references to the (private) implementation in System.Private.CoreLib.dll defined here. For example the System.Runtime package defined in CoreFX declares the PUBLIC name for types like System.Object and System.String. Thus from an applications point of view these types live in System.Runtime.dll. However, System.Runtime.dll (defined in the CoreFX repo) forwards references ultimately to System.Private.CoreLib.dll which is defined here
What I understand from it (not sure), is that every type in CoreCLR (like String) is defined twice, one in the CoreCLR (the actual definition), and the other in the CoreFX, which is facade definition, that eventually points to the packaged CoreCLR (System.Private.CoreLib.dll), and that the pakage Microsoft.NETCore.Runtime.CoreCLR that shows up in NuGet, isn't useful beacuse I only can access it through the CoreFX.
I hope someone either confirm that or correct me.

Specflow with Autofac - Unable to load TechTak.Specflow.Infrastructre.IBindingInstanceResolver Version=2.2.0.0

I have a project that uses Autofac for constructor level injection. For every service instance, repositories are injected to constructor.
Now to start using SpecFlow for the project I am not able to instantiate the service for method calls. I have already added Specflow.Autofac plugin but now I am getting following error. I have checked all referenced assemblies versions and those are correct.
I think you are using SpecFlow.Autofac. Is this correct?
If so, it doesn't work with SpecFlow 2.2 at the moment.
For details have a look at this issue: https://github.com/techtalk/SpecFlow/issues/959

"WebSecurity" does not exist in the current context error in _AppStart.cshtml

I am getting the following compilation error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'WebSecurity' does not exist in the current context
Source Error:
Line 1: #{
Line 2: if (!WebSecurity.Initialized)
Line 3: {
Line 4: WebSecurity.InitializeDatabaseConnection("AreaProject", "User", "UserId", "EmailAddress", autoCreateTables: true);
Source File: c:\Projects\area\trunk\dotNet\area.Web\area.Web\_AppStart.cshtml Line: 2
enter code here
My project is correctly referencing to "System.Web" and my other files that are using " System.Web.Security" are compiling fine.
The problem started when I added the references System.Web, System.Web.Pages and System.Web.Razor to my application. But I didn't make any change to WebMatrix.WebData or WebMatrix.Data.
The WebSecurity class that is being referenced here is apart of WebMatrix.WebData and not System.Web or System.Web.Security. You probably need to add a reference to WebMatrix.WebData.dll and things should at least get past the runtime compiler error.
You get the compiler error at runtime because views are normally compiled when the application starts up for the first time, instead of when the assemblies are complied.
I'm assuming you are trying to run the MVC4 application first time.
MVC4 adds boatload of assembilies for Internet Application template. It becomes PIA to remove them if you do not use it.
Basically, if you do not use WebMatrix or OAuth to authenticate, you can just comment out everything inside SimpleMembershipInitializer class.
private class SimpleMembershipInitializer
{
// Comment out everything
}
Just for testing, you can also comment out every line inside AccountController that throw exception.
Old thread, but just in case it helps someone down the road. I am not sure why it works this way, but sometimes installing packages like WebMatrix.WebData, WebMatrix.Data is not enough. When I look at the Reference section of my application after these assemblies were installed, WebMatrix.WebData, WebMatrix.Data were still not showing up there, although they were in the BIN folder of the application. I had to literally use Add Reference to make them. Only then, they shown up and everything started working.

MVC2 with Ninject.Web.Mvc 2.2 and Ninject 2.2 runtime version 4.0 always asks for parameterless constructor for controllers

I have a previous project running Ninject 2.0 runtime version 2.0 and now I am using Ninject in a new project and using the new Ninject, ninject web.mvc version 2.2 for runtime version 4.0.
Every single time I get the error no parameterless constructor
Invalid Operation exception
An error occurred when trying to create a controller of type HomeController'. Make sure that the controller has a parameterless public constructor.
What am I missing. All the bindings are registered.
Do I need to now define interfaces for Controllers as well such as HomeController as IHomeController as I have seen in some examples, Or do I get back to using the older version
There is one version that does not show activation exceptions properly but show this exception instead. Most likely the problem is a duplicated binding.
In addition to what Remo Gloor said, you might want to check that MVC is set up to use Ninject correctly. I was doing some things manually on an older version of the MVC plugin and ended up needing to just bite the bullet and make Global extend the NinjectHttpApplication class, which I had previously been avoiding.
The error you're getting is the error you would get if MVC tries using its built-in controller factory to produce controllers. So you may want to create a custom method binding on your controller class and put a breakpoint inside to make sure it's even being invoked.
You may also want to switch to version 2.3. You can pick up the latest builds of Ninject and all its extensions here.
I have seen this issue mentioned couple of times on forums where there is no direct answer, here is the solution to the above problem, i.e., working with latest ninject
Download the latest Ninject from github.
The ninject I got for MVC2 is named as Ninject.Web.Mvc2-2.2.0.0-release-net-4.0 (runtime version 4)
Now during adding reference add Ninject.Web.Mvc.dll(check the version is same as above by right click properties in VS)
Now Add Ninject.dll from the lib folder in same parent folder (check the version as above)
Now Add CommonServiceLocator.NinjectAdapter.dll from the extensions folder in lib parent folder (check the version as above.)
The missing link in all these have been the commonserviceLocator.dll and the correct version should match. This should be tried if you are sure your bindings are correct as mine were and check to see if your project work with older version.
Thanks to everyone, and good luck :)

Resources