Been fighting this one all morning. Here are the links I have been pointed to and I am still having no luck:
http://www.asp.net/visual-studio/overview/2013/release-notes-(release-candidate)
https://stackoverflow.com/a/18426574/1118218 (I did everything the accepted answer suggests)
https://stackoverflow.com/a/18419011/1118218 (same question as above, but the solution here did not work either, does not resolve the classes)
I installed the ASPNET web tools refresh. Restarted visual studio. Everything seems to build correctly except for the AccountController. It cannot find AuthenticationIdentityManager(and IdentityStore).
[Authorize]
public class AccountController : Controller
{
public AccountController()
{
IdentityManager = new AuthenticationIdentityManager(new IdentityStore());
}
public AccountController(AuthenticationIdentityManager manager)
{
IdentityManager = manager;
}
public AuthenticationIdentityManager IdentityManager { get; private set; }
}
Any idea how to get this to work? All the nuget packages related to ASP.NET Identity, Owin, EF, and MVC are updated to the latest pre-release version.
Depending on the operation you are looking to achieve here? you can get the current authentication manager via
var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
which will then let you do things like
authenticationManager.SignOut();
the AuthenticationIdentityManager and the IdentityStore classes no longer exist.
The AccountController you are using seems to be generated by an older VS2013 version. The easiest way to make this work with the latest ASP.NET Identity version is by creating a new MVC Project with individual accounts using the release version of VS2013. This will create an AccountController class that is compatible with the latest ASP.NET Identity assemblies. Then replace your AccountController with the one you just generated.
Related
After reviewing my options regarding saving JWT token, I chose Xamarin.Essentials Secure Storage.
Problem being that my app always breaks when trying to save a token within the storage with the following error:
"System.AggregateException has been thrown"
The details are as follow:
"Xamarin.Essentials.NotImplementedInReferenceAssemblyException
This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation."
This clearly means that something went wrong in the installaion of the nuget package, so I:
Uninstalled and reinstalled the xamarin.essentials package.
Upgraded .Netstandard to 2.0, thinking that 1.6 wasn't compatible.
Checked if the package is referenced within the csproj file.
So forth, nothing.
For now, I have a TokenStorageController with the following lines of codes :
public bool SaveToken(string token)
{
if(token != null)
{
Preferences.Set(key, token);
if(Preferences.ContainsKey(key))
{
return true;
}
}
return false;
}
The RestService class from where the controller gets called looks like this :
//await SecureStorage.SetAsync("oauth_token", "booommmmmm"); // changed to this simply to check if my controller was the problem
TokenStorageController tokenStorage = new TokenStorageController();
await tokenStorage.SaveToken("boommmmm"); // where I get an error
And here is the exact line where the error occurs:
var loginTask = Task.Run(() => restService.LoginAsync(user)).Result;
If no solutions, I will remove all packages and reinstall them all. ONE BY ONE! I swear I'll do it!
And if no solutions at all, I will store the token within SQL as I already have a controller in place to do so.
I am a Xamarin and C# noob so bear with me please.
FYI: I am using a macOS client for testing purposes, as the cause could be that SecureStorage doesn't work for macOS apps.
Thanks!
Xamarin.Mac is not currently a supported platform, just iOS, Android, UWP.
The code is available for review at:
https://github.com/xamarin/Essentials/tree/master/Xamarin.Essentials/SecureStorage
I have a very simple WebAPI 2 controller running on .NET Framework 4.6.2, that looks like this:
[RoutePrefix("Invitations")]
public class InvitationsController : CqrsApiController
{
[HttpPost, Route("Clients/{id:long}/Actions/Cancel")]
public IHttpActionResult PostClientInvitationCancel(long id, [FromBody] ClientInvitationCancelCommand command)
{
Execute(command);
return SeeOther("Invitations/Clients/{0}", id);
}
}
and am trying to write an NUnit test for it, like this:
[TestFixture]
public class WhenExecutingAValidCommand
{
[Test]
public void ItShouldReturnARedirect()
{
var dispatcher = Substitute.For<ICqrsDispatcher>();
var urlHelper = Substitute.For<UrlHelper>();
urlHelper.Link(Arg.Any<string>(), Arg.Any<object>()).Returns("https://tempuri.org/");
var sut = new InvitationsController(dispatcher);
sut.Request = new HttpRequestMessage();
sut.Configuration = new HttpConfiguration();
sut.Url = urlHelper;
var response = sut.PostClientInvitationCancel(1, new ClientInvitationCancelCommand());
response.Should().BeOfType<SeeOtherRedirectResult>();
}
}
```
However, when I run the test, I get the following error:
System.MissingMethodException : Method not found: 'Void System.Web.Http.ApiController.set_Request(System.Net.Http.HttpRequestMessage)'.
at ApiProjectTests.InvitationsControllerTests.WhenExecutingAValidCommand.ItShouldReturnARedirect()
The same code seems to work fine in similar projects based on .NET Framework 4.5.1, so I'm wondering if there's some sort of DLL hell going on here. System.Web.Http is using Microsoft.AspNet.WebApi.Core.5.2.3, whereas System.Net.Http is coming from the GAC (well, C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\System.Net.Http.dll to be more precise).
Update: if I try to debug into the unit test, the error occurs before I even enter the method. So although VS2017 compiles the tests just fine, when the test runner fires up, then everything falls apart. Sounds more like DLL hell to me.
Update 2: if I comment out the setting of the request, then I can debug into the test method. If I then put in a breakpoint, and then use the Immediate window to directly set the request property, it works, and there is no Method not found error. I also disabled Resharper and used VS2017's Test Explorer to run the tests, in case R# was caching something, but it made no difference.
It looks like my problem is indeed DLL hell, more specifically the DLL hell referenced by https://github.com/dotnet/corefx/issues/25773. The issue is caused by other NuGet packages that contain references to the newer version of System.Net.Http (4.2.0.0). The current solution appears to be to add a binding redirect to downgrade the assembly version to the expected version (4.0.0.0), but so far that has not helped me.
The solution that did work for me was to install the latest NuGet package of System.Net.Http, and use assembly binding redirects in my test project to ensure that it used the 4.2.0.0 version instead of 4.0.0.0.
This is often caused by early versions of nuget packages targeting .NET standard, which have dependencies on OOB ("out-of-band") packages. OOB packages are a kind of polyfill for dlls that are part of .NET framework but not .NET standard. Here is a very good explanation of what happened. In my case, the following helped:
I identified the nuget package that had a dependency on the system.net.http 4.2.0 nuget package, and upgrade that package.
The dependency was no longer present in the upgraded package, so i could uninstall the system.net.http 4.2.0 nuget package.
The upgraded package of course still expects the reference to the system.net.http 4.0.0 assembly, so in case of doubt, you may reinstall the upgraded package to make sure that the assembly reference is in your *.csproj file.
Having the code below in VisualStudio 2017 .NET Core 2.0 Console App
using System;
using System.Security.Principal;
namespace smallTests
{
class Program
{
static void Main(string[] args)
{
var identity = WindowsIdentity.GetCurrent();
}
}
}
Why am I getting the error:
The name 'WindowsIdentity' does not exist in the current context
If I can see this class in .NET Core 2.0 library in .Net Core docs ?
Same code works in .NET Console app.
[EDIT]
#Will #JohnnyL Commented that I do not refer, System.Security.Principal.Windows.dll, that is true.
But I am curious why it is not working, because
in .NET 4.6.1 project (where class WindowsIdentity is visible) I also do not refer this System.Security.Principal.Windows.dll specifically. However i refer System.dll.
I always thought that it works like namespace hierarchy. For instance, when I refer to
System.Security.Principal.dll
i can use class which is in
System.Security.Principal.Windows.dll.
Am I wrong?
I added System.Security.Principal.dll to .NetCore solution by hand but it still does not work.
[EDIT2]
#Will Thank you a lot for expaining the subject it helped me a lot.
I tried to figure out is WindowsIdentity compatible with Core and it seems that it is please see:
in this apisof.net in Declarations area i can see that WindowsIdentity is in .Net Core 2.0 System.Security.Principal.Windows, Version=4.1.1.0, PublicKeyToken=b03f5f7f11d50a3a
but i do not have System.Security.Principal.Windows.dll in references, should I add it? If yes from where?
in .NET Core api reference i see this class in the list (what is the purpose of that listing if it is not compatible with core?
I also find information about that class in that link
Am I looking in wrong places?
Microsoft announced Windows Compatibility Pack for .NET Core a few weeks ago,
https://blogs.msdn.microsoft.com/dotnet/2017/11/16/announcing-the-windows-compatibility-pack-for-net-core/
And by analyzing the source code of System.Security.Principal.Windows.csproj and the commit adding it,
https://github.com/dotnet/corefx/blob/master/src/System.Security.Principal.Windows/src/System.Security.Principal.Windows.csproj
My conclusion is that this is also part of the Windows only compatibility libraries, so can only be used on Windows.
To add that to your project, open your csproj and add a PackageReference tag for System.Security.Principal.Windows manually (or use Visual Studio's NuGet Package Manager).
When setting up LightInject for an MVC controller I am getting an error when calling container.EnableMvc(); in the injector setup.
Error:
Method not found:
'Void LightInject.WebContainerExtensions.EnablePerWebRequestScope(LightInject.IServiceContainer)'
Source:
public static void Register() {
var container = new ServiceContainer();
container.ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider();
WebContainerExtensions.EnablePerWebRequestScope(container);
container.RegisterControllers();
container.Register<ISomeClass, SomeClass>();
container.EnableMvc();
}
Additional Information:
I am running the code locally through Visual Studio
The project is 4.5
My OS is Windows 10 (framework 4.5)
In the past when I have setup LightInject I have set the scope lifetime manually but the documentation, for general setup and MVC specific examples, has since changed. I came across one thread that mentioned this could be an issue with not including LightInject.Web as a dep, but I can see it listed as a dep for LightInject.MVC and in the list of references in the project.
Are there any other steps I can take to manually configure the lifetime or otherwise verify that this method is available before Enabling MVC?
The issue here was that I installed LightInject.MVC with NuGet. It lists it's dependencies as:
LightInject.Web (>= 1.0.0.4)
LightInject (>= 3.0.1.7)
The after I exhausted this being an issue with versions of .Net 4.5 and possible issues with async. I decided to manually update both LightInject.Web and LightInject to their newest versions. After the update it resolved the issue.
I will add this as a bug in the listed dependencies on the projects site.
All my searches are coming back to the same one of two issues, which aren't the problem in this project. I've never had trouble with this before, but this particular project is being weird.
First off, the project name is Site. The class SiteContext inherits DbContext.
When I run Enable-Migrations, even explicitly , the Package manager console returns an error:
PM> Enable-Migrations -ContextType SiteContext
The context type 'SiteContext' was not found in the assembly 'Site'.
But it's right there in the code:
// Not in a namespace or anything
public class SiteContext : DbContext {
// public DbSets in here
}
I can use SiteContext anywhere in my site's code, access the database though an object of it, etc. It's only the Enable-Migrations command that can't find it. Other than this, Entity's code-first functionality is working properly.
Any ideas what might be going on? Where did I mess this up?
(Entity Framework 6.0.2 / Web Pages 3.1.1)
ASP.NET Web Pages sites are built using the Web Site project type. This project type doesn't support Entity Framework Migrations. If you want to use Code First Migrations with an ASP.NET Web Pages site, you need to develop your data access code as a separate class library. That project type does support EF Migrations. I've blogged about it here: http://www.mikesdotnetting.com/Article/217/Code-First-Migrations-With-ASP.NET-Web-Pages-Sites
Instead of -ContextType, use -ProjectName and Specify Site.
Edit: First, try -ContextTypeName. I have to assume you didn't.