Search code examples
c#.netxamarinuwpisolatedstorage

Could not load file or assembly 'System.Runtime.Handles' - Xamarin UWP


We use Isolated storage throughout our code and it has always worked fine. Suddenly this error has started coming up in a few different projects and it means that I can't use Isolated Storage at all. I tried adding the System.Runtime.Handles NuGet package but it has made no difference.

This is the code:

        using (var userStore = IsolatedStorageFile.GetUserStoreForApplication())
        {
        }

System.IO.IsolatedStorage.IsolatedStorageException occurred
HResult=0x80131450 Message=Operation not permitted. Source= StackTrace: at System.IO.IsolatedStorage.IsolatedStorageFile.CreatePathPrefixIfNeeded(String path) at System.IO.IsolatedStorage.IsolatedStorageFile.FetchOrCreateRoot()
at System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStore() at System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication() at Adapt.Presentation.XivicControls.XivicUtilities.CreateAttachmentsFolders() in C:\AdaptSource\Xivic\Adapt.Presentation.XamarinForms\Adapt\Presentation\XivicControls\XivicUtilities - Xamarin Forms.cs:line 19 at Adapt.Presentation.XamarinForms.App.d__31.MoveNext() in C:\AdaptSource\Xivic\Adapt.Presentation.XamarinForms\Adapt\Presentation\XamarinForms\App.xaml.cs:line 99

Inner Exception 1: FileNotFoundException: Could not load file or assembly 'System.Runtime.Handles, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

But, this is also a compile time problem. I am getting this compiler error message in a separate project:

Severity Code Description Project File Line Suppression State Error Could not copy the file "C:\Users\chris.nuget\packages\runtime.any.System.Runtime.Handles\4.3.0\lib\netstandard1.3\System.Runtime.Handles.dll" because it was not found. TestXamarinForms.UWP C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets 4222

You can easily see the error if you check out my repo here: https://[email protected]/ChristianFindlay/xamarin-forms-scratch.git


Solution

  • This problem has been resolved without having to do anything. I can't explain how it was resolved, but I suspect it was a problem with Appx installation. I believe that the installation of the app somehow got corrupted, and therefore the isolated storage was also corrupted. I started another thread here for a different reason:

    UWP App Won't Start

    The answer that I needed to uninstall the app through powershell like this because the app somehow got installed with a different username:

    Get-appxpackage -allusers <appname> | Remove-AppxPackage
    

    Isolated storage now works. Magically, the compilation error I was getting with the same error message has cleared up as well. This is all still somewhat of a mystery.