When upgrading to the latest versions of the asp.net-5 stack, I encountered the following stack trace while attempting to access my SignalR hub.
FileNotFoundException: Could not load file or assembly 'Microsoft.AspNet.Security.DataProtection, Version=22.214.171.124, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
System.Type.GetType(String typeName, Boolean throwOnError)
Microsoft.AspNet.DataProtection.KeyManagement.KeyRingProvider.CreateCachedKeyRingInstanceUnderLock(DateTime utcNow, CachedKeyRing existingCachedKeyRing)
Microsoft.AspNet.SignalR.Infrastructure.DataProtectionProviderProtectedData.Protect(String data, String purpose)
I understand that this assembly has been renamed Microsoft.AspNet.DataProtection and I see from the aspnet github repositories that this change SEEMS to have rippled through the other projects.
I have deleted all references to the old assembly, searched the ENTIRE contents of the .k directory, my project directory, my GAC, EVERYTHING.Answer1:
Of course, after 4 hours of trying to figure this out, I discover the bizarre cause of it right after I post the question:
The reason why scouring my entire hard drive for any possible mention of the old assembly turned up nothing is because the reference to it was cleverly ENCRYPTED in an XML file in my %APPDATA% directory created by the old version of the assembly!
When upgrading to the new version with the new assembly name, you MUST delete the contents of the directory: %APPDATA%\Local\ASP.NET\keys-BETA or you will end up with this error! The xml file in this directory contains an encrypted representation of the assembly-qualified classname of the decryptor, which will be using the old "Security.DataProtection" assembly instead of the new one.Answer2:
Similar to Avi Cherry, I found I had this problem moving from .NET Core (DNX) RC1 to (DotNet) RC2.
The directory I needed to delete was
The xml inside referenced
Microsoft.AspNet.Security.DataProtection, which was should have been
Microsoft.AspNetCore.... Instead of trying to change it, I just removed the directory.
I can't comment on the other answers, so need to add my own. As others have said you need to delete the CONTENTS of the %localappdata%\ASP.NET\DataProtection-Keys directory.
But do NOT delete the entire folder. This can cause issues for dotnetcore apps later. Visual Studio may say "debugging is starting" and just hang.