Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly 'Microsoft.AspNet.Security.DataProtection'

Tags:

asp.net-core

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=1.0.0.0, 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.XmlKeyManager.ParseKeyElement(XElement keyElement) Microsoft.AspNet.DataProtection.KeyManagement.XmlKeyManager.GetAllKeys() Microsoft.AspNet.DataProtection.KeyManagement.KeyRingProvider.CreateCachedKeyRingInstanceUnderLock(DateTime utcNow, CachedKeyRing existingCachedKeyRing) Microsoft.AspNet.DataProtection.KeyManagement.KeyRingProvider.GetCurrentKeyRing() Microsoft.AspNet.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(Byte[] unprotectedData) 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.

like image 851
Avi Cherry Avatar asked Feb 27 '15 02:02

Avi Cherry


Video Answer


2 Answers

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.

like image 106
Avi Cherry Avatar answered Sep 24 '22 23:09

Avi Cherry


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 %localappdata%\ASP.NET\DataProtection-Keys.

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.

like image 41
TylerY86 Avatar answered Sep 22 '22 23:09

TylerY86