Aspnetcore.Identity.EntityFramework 6.0.9 , SignInManager doesn't work - asp.net-web-api

I'm using Microsoft.AspNetCore.Identity.EntityFrameworkCore 6.0.9 Nuget package and I can't use SignInManager method.
Has this method been replaced by another method or am I making a mistake at some point?
I Added this code in Program cs
builder.Services.AddIdentity<AppUser, AppRole>().AddEntityFrameworkStores<AppDbContext>();
SignInManager asks me to install AspNetCore.Identity while UserManager works with nuget package I installed

Related

Why is a Namespace not included in resulting nuget package after 'nuget pack' and including it in another project

I have a .net 6.0 class library project that has class files in the root, but also contains a Models folder with public classes declared in the class library. I've tried using the *.nupkg file created via nuget pack at the *.csproj level and the one created when the build preference to generate a package on every build. The package is created fine as MyPackage.
When I include 'MyPackage' in another project, I have access to the root classes, but the namespace MyPackage.Models doesn't seem to be included even though it was part of the project. Additionally, the xml documentation file does not seem to be included because I see none of my comments included when calling any of the methods on classes at MyPackage root.
I'm new to using my own nuget packages so this might be a rookie mistake, but I'm not sure what I'm doing wrong here.
Any advice?
I make a test to create a MyPackage package and can correctly reference the namespace MyPackage.Models, here is the project:
I add this code in Method1.cs:
namespace MyPackage.Models
{
public class Method1
{
public int Add(int a,int b)
{
return a + b;
}
}
}
It works in the test:
Maybe you can provide some more information to help reproduce the problem.
The problem was a nuget package caching issue. I had to close out my solutions, clear the cache, and even reboot my machine. When I did that, things worked as I expected.
Before I tried this, I created a new class library project and copied the files from the prior project to this one. When I made a nuget package for this new one, everything worked as intended. That confirmed for me that the issue was caching.

Unable to install NuGet pck - Microsoft.Web.Infrastructure is not in my GAC

The error:
Failed to add reference. The package 'SimpleInjector.Integration.WebApi.WebHost.QuickStart' tried to add a framework reference to 'Microsoft.Web.Infrastructure' which was not found in the GAC. This is possibly a bug in the package. Please contact the package owners for assistance.
Cannot find assembly 'Microsoft.Web.Infrastructure'.
First of all. Why the error when I have the dll and reference to it in my project?
Second. How do I fix this?
Obviously I've tried to add the assembly to my GAC with various guides from Mircosoft. None of them makes sense imo.
https://learn.microsoft.com/en-us/dotnet/framework/app-domains/how-to-install-an-assembly-into-the-gac
This results in "Failure adding assembly to the cache: The system cannot find the file specified." I guess that's because it's not a strongly typed name with a key pair or what ever. So I looked into this https://learn.microsoft.com/en-us/dotnet/framework/app-domains/how-to-sign-an-assembly-with-a-strong-name
which makes absolutely no sense. It says:
"In the Choose a strong name key file box, choose , and then navigate to the key file. To create a new key file, choose and enter its name in the Create Strong Name Key dialog box."
What key file? Create a new and just come up with a random name? Wtf? How is that related to a specific assembly?
I faced a similar issue with error "Unable to uninstall 'Ninject.3.2.2' because 'Ninject.Extensions.ChildKernel.3.2.0, Ninject.Extensions.Conventions.3.2.0, Ninject.Web.3.2.0, Ninject.Web.Common.3.2.0' depend on it.".
It was caused by multiple projects in the solution having a dependency on those DLLs and so package manager was not able to uninstall it.
The command with "uninstall package-name -RemoveDependency" too doesn't work here.
I removed the dependency one by one to fix it.
As #Schadensbegrenzer and #LeoLiu-MSFT pointed out, the Infrastrcuture assembly is not part of the .NET framework (anymore).
The issue has been reported as a bug on SimpleInjectors repo:
https://github.com/simpleinjector/SimpleInjector/issues/509
The package owners solution:
"I'll add this issue to the v4.1 backlog, and will fix the NuGet package (and that of SimpleInjector.Integation.MVC3 as well) with v4.1.
In the meantime, you can manually add the Microsoft.Web.Infrastructure NuGet package to your Web API project or don't add the SimpleInjector.Integration.WebApi.WebHost.QuickStart NuGet package to your project, but just the SimpleInjector.Integration.WebApi NuGet package and add the required code manually. The WebHost.QuickStart package is in fact nothing more than a reference to the integration package while injected some code into your application anyway.
The Web API integration page in the documentation describes how to set up a Web API project using Simple Injector."

"Object reference not set to an instance of an object." with NuGet.VisualStudio.IVsPackageInstaller.InstallPackage

The following code is raising NullReferenceException ("Object reference not set to an instance of an object.") on Visual Studio 2015, NuGet.VisualStudio v3.3).
try
{
this.PackageInstaller.InstallPackage(packageSource, project, packageId, version, ignoreDependencies);
}
catch (Exception ex)
{
string error = string.Format(CultureInfo.CurrentCulture, Properties.Resources.RES_Error_InstallingNuGetPackage, packageId, project.Name);
throw new NuGetServiceException(error, ex);
}
The PackageInstaller is an instance of NuGet.VisualStudio.IVsPackageInstaller.
The problem seems to have something to do with the values of version, and may be packageSource.
When this error is raised the values are:
packageSource = "All"
version = null
If I change the value of version to the latest available version of the package ("3.00.00.1041") then the exception is InvalidOperationException ("Unable to find version '3.00.00.1041' of package 'Primavera.Core.Patterns.Models'.").
This does not make any sense because this works perfectly in the Package Manager Console and it installs exactly that version. It seems to be a bug in the NuGet.VisualStudio code base.
Any ideas?
This question has been discussed on GitHub, but the short answer is that you should use a null source instead of "All" because the "All" keyword has no special meaning in the 3.x NuGet Visual Studio extension. Using null is the recommended way of installing a package from the user's configured package sources.
Note that this can be a brittle way of installing packages since the user's configuration is typically unpredictable from the VSIX developer's point of view. A more reliable way of installing a package is by explicitly specifying the package source (and even version) when installing.

I am having issues with Ninject and MVC 5 Web api 2.2

I tried the solution in MVC5, Web API 2 and and Ninject but the package breaks my build(System.Web). I have also tried the "Ninject.MVC3" Package. When i fix it with "Update-Package -reinstall Microsoft.AspNet.WebApi.WebHost", I get the error:
An error occurred when trying to create a controller of type error: 'AnyController'. Make sure that the controller has a parameterless public constructor.
I have installed, reinstalled, uninstalled-installed all the of the packages multiple times.
My NinjectWebCommon.cs is vanilla except for the following:
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IMonitoringConfigurationService>()
.To<MonitoringConfigurationService>();
}
I Would be very grateful for any help
Not sure what the cause of your problem is, as the latest releases of Ninject are virtually plug-n-play. Make sure you have installed the following Nuget packages. If you've got other versions or anything weird uninstall them:
Ninject
Ninject.MVC5
Ninject.Web.WebApi
Ninject.Web.Common (Added by Ninject.Web.WebApi)
Ninject.Web.Common.WebHost (Added by Ninject.MVC5)
Anything else is unnecessary and should be removed. The last two packages are installed as dependencies, so really all you should have to install explicitly is Ninject.MVC5 and Ninject.Web.WebApi. Either will install the Ninject base package.
Once you've got the right packages, then it basically boils down to your config in NinjectWebCommon.cs. The only method you need to modify is RegisterServices, and there, you'll need to add any and all bindings your project needs. If you're getting an error saying you need a parameterless constructor, that just means you haven't added the binding that the constructor needs.

Why can't I reference one project from another (but CAN use statics)?

This one is weird. I've got a MonoDevelop/MonoTouch project (call it MyApp) that references another project (call it MyUtils), which is a Portable Class Library (targeting .NET 4.0.3, if that is relevant).
In the MyApp project, I've added a reference to MyUtils. In Visual Studio, this works properly: I can refer to the classes in MyUtils without any problem.
But in MonoDevelop on the Mac, if I try to refer to MyUtils from MyApp, I can't. It simply doesn't see the project, and can't, for instance, write something like:
using MyUtils.MyNamespace
If I do, I get a 'type or namespace could not be found' error.
But here's the weird part: MyApp can use the static classes in MyUtils. If I refer to a public static class in MyUtils from MyApp, it works! What could possibly explain this?!
What explains this is that the MonoTouch implementation of PCLs is a bit of a kludge at present.
The proper work is underway, but in the meantime you need to use an interim release of MonoDevelop, and you need to be aware that things like Intellisense and syntax highlighting don't really work in MonoDevelop.
See:
MonoTouch: creating multiplatform apps using Portable Class Libraries
http://slodge.blogspot.co.uk/2013/02/the-future-is-portable.html
Update - the interim release is hidden in a comment on that question:
For those doing PCL stuff, I've posted a patched MonoDevelop 3.1.1 build with improved PCL support here: http://files.xamarin.com/~jeff/MonoDevelop-3.1.1.dmg - it's still not perfect, but it's better than the official builds so far (my patches will be in a future official release) – jstedfast Feb 8 at 14:57

Resources