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

1

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://ChristianFindlay@bitbucket.org/ChristianFindlay/xamarin-forms-scratch.git

c#
.net
xamarin
uwp
isolatedstorage
asked on Stack Overflow Oct 18, 2017 by Christian Findlay • edited Oct 18, 2017 by Christian Findlay

2 Answers

0

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.

answered on Stack Overflow Oct 23, 2017 by Christian Findlay
-1

As far as I know IsolatedStorage is not supported in Xamarin apps. You should use native storage mechanism on each platform to store files/data/settings - like described here https://developer.xamarin.com/guides/ios/application_fundamentals/working_with_the_file_system/ .

For UWP you will want to use System.IO.File or Windows.Storage to store and manage files.

answered on Stack Overflow Oct 18, 2017 by Martin Zikmund

User contributions licensed under CC BY-SA 3.0