You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IsolatedStorageFile.GetUserStoreForApplication path changes between Xamarin.iOS and .NET 6 builds on iOS #74642
The path of a file created by IsolatedStorageFile.GetUserStoreForApplication() changes between Xamarin.iOS and .NET 6, and also changes between different builds of the application under .NET 6.
This makes IsolatedStorageFile unusable in .NET 6 since an updated build cannot open a file created by a previous build. Each time the build is updated, all of the files previously created on behalf of the user are effectively gone.
For example, the following code:
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) {
using (IsolatedStorageFileStream stream = store.OpenFile("settings.txt", FileMode.Create)) {
// Write file contents here
results in the file being written to various locations in the iOS device file system depending on the build of the application:
In Xamarin.iOS the path of the file was consistent across builds of the app.
Reproduction Steps
Build the code below on Xamarin.iOS and execute on an iOS device.
Migrate the app to dotnet 6, rebuild and execute on the same iOS device.
Note that the file is created in a different file system location on the device.
Clean and rebuild the dotnet 6 app and execute on the same iOS device.
Note that the file is created in yet another file system location on the device.
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) {
using (IsolatedStorageFileStream stream = store.OpenFile("settings.txt", FileMode.Create)) {
}
}
Expected behavior
The settings.txt file should be created in the same file system location (path) for every version of the built application.
Actual behavior
The settings.txt file is created in a different file system location (path) for every version of the built application on dotnet 6
Regression?
Yes, this is a regression. The file system path for IsolatedStorageFile was consistent in .NET Framework applications I've built over the past decade with many different versions of .NET and Xamarin.iOS.
Known Workarounds
I don't know of any workaround using the .NET 6 IsolatedStorageFile API. Applications would have to use some other file system API and maybe Environment.GetFolderPath(SpecialFolder folder).
As a workaround, this path can be recreated manually in .NET 6 using Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) as the base path and appending ".config/.isolated-storage/".
Legacy files can then be accessed using System.IO.File instead of IsolatedStorageFile.
changed the title [-]IsolatedStorageFile.GetUserStoreForApplication path changes between Xamarin.iOS and dotnet 6 builds on iOS[/-][+]IsolatedStorageFile.GetUserStoreForApplication path changes between Xamarin.iOS and .NET 6 builds on iOS[/+]on Aug 27, 2022
As a workaround, this legacy path can be recreated manually in .NET 6 using Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) as the base path and appending ".config/.isolated-storage/".
Legacy files can then be accessed using System.IO.File instead of IsolatedStorageFile.
Hi @dtaylorus,
I was trying to reproduce it locally from both runtime and from maui app, but still I can see after several builds same URl."hash". Here are my steps from maui.
Created Maui app and added these lines
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) {
using (IsolatedStorageFileStream stream = store.OpenFile("settings.txt", FileMode.Create)) {
// Write file contents here
Tried several times clean/build, uninstalling app from phone but the root is still the same.
This was what I saw for several builds
"/data/user/0/com.companyname.testmaui/files/IsolatedStorage/0h0aylru.guc/lh5b4jf5.cnu/Url.kvaj4cxhwjeypoiko55puloz0kgusnnw/AppFiles/"
I'm trying on Android device, running on Debug mode using Visual Studio 2022 for Mac v17.4 Preview. (For release mode unfortunately I still have exception while running, working on it)
Could you please add more details which mode are you running and if possible upload your project ?
Probably the simplest thing to do is create the same project for legacy Xamarin.Android (not .NET 6) and see that the path is completely different and doesn't even contain the 'Url' part of the path that is new in .NET 6 for Android.
This means that projects that were released on legacy Xamarin.Android will lose access to files created with IsolatedStorageFile after upgrading the project to .NET 6.
If this backward compatibility issue is fixed, the part of this issue about the path constantly changing will be irrelevant anyway since there won't be a Url part of the path that can change.
Also note that I found the behavior about the path changing on .NET 6 for iOS, not Android. I only verified that the backward compatibility issue exists on Android (where the path changes between Xamarin.Android and .NET 6 for Android). I have not tested for the changing path between builds on Android being the same as on iOS.
Hope that makes sense. Thanks for looking into this issue
To answer your specific questions, I'm building on Visual Studio 2022 for Windows. My Android builds are local (SDK version 33) and my iOS builds are via a remote connection to a MacOS machine. I've tested in both debug and release builds and the results appear to be the same.
My project is a released app that is way too big to share. I encountered this problem when I was forced to upgrade the project to .NET 6 because of some dependencies. I was able to work around the issue by replacing all references to IsolatedStorageFile with direct use of System.IO.File.
Activity
dtaylorus commentedon Aug 26, 2022
The legacy IsolatedStorageFile.GetUserStoreForApplication() folder on Xamarin.iOS is:
As a workaround, this path can be recreated manually in .NET 6 using
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)as the base path and appending".config/.isolated-storage/".Legacy files can then be accessed using
System.IO.Fileinstead ofIsolatedStorageFile.[-]IsolatedStorageFile.GetUserStoreForApplication path changes between Xamarin.iOS and dotnet 6 builds on iOS[/-][+]IsolatedStorageFile.GetUserStoreForApplication path changes between Xamarin.iOS and .NET 6 builds on iOS[/+]dtaylorus commentedon Aug 27, 2022
This is broken in the same way on Android. The legacy IsolatedStorageFile.GetUserStoreForApplication() folder on Xamarin.Android is:
As a workaround, this legacy path can be recreated manually in .NET 6 using
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)as the base path and appending".config/.isolated-storage/".Legacy files can then be accessed using
System.IO.Fileinstead ofIsolatedStorageFile.mkhamoyan commentedon Aug 30, 2022
Hi @dtaylorus,
I was trying to reproduce it locally from both runtime and from maui app, but still I can see after several builds same URl."hash". Here are my steps from maui.
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) {
using (IsolatedStorageFileStream stream = store.OpenFile("settings.txt", FileMode.Create)) {
// Write file contents here
This was what I saw for several builds
"/data/user/0/com.companyname.testmaui/files/IsolatedStorage/0h0aylru.guc/lh5b4jf5.cnu/Url.kvaj4cxhwjeypoiko55puloz0kgusnnw/AppFiles/"
I'm trying on Android device, running on Debug mode using Visual Studio 2022 for Mac v17.4 Preview. (For release mode unfortunately I still have exception while running, working on it)
Could you please add more details which mode are you running and if possible upload your project ?
dtaylorus commentedon Aug 30, 2022
Probably the simplest thing to do is create the same project for legacy Xamarin.Android (not .NET 6) and see that the path is completely different and doesn't even contain the 'Url' part of the path that is new in .NET 6 for Android.
This means that projects that were released on legacy Xamarin.Android will lose access to files created with IsolatedStorageFile after upgrading the project to .NET 6.
If this backward compatibility issue is fixed, the part of this issue about the path constantly changing will be irrelevant anyway since there won't be a Url part of the path that can change.
Also note that I found the behavior about the path changing on .NET 6 for iOS, not Android. I only verified that the backward compatibility issue exists on Android (where the path changes between Xamarin.Android and .NET 6 for Android). I have not tested for the changing path between builds on Android being the same as on iOS.
Hope that makes sense. Thanks for looking into this issue
dtaylorus commentedon Aug 30, 2022
To answer your specific questions, I'm building on Visual Studio 2022 for Windows. My Android builds are local (SDK version 33) and my iOS builds are via a remote connection to a MacOS machine. I've tested in both debug and release builds and the results appear to be the same.
My project is a released app that is way too big to share. I encountered this problem when I was forced to upgrade the project to .NET 6 because of some dependencies. I was able to work around the issue by replacing all references to IsolatedStorageFile with direct use of System.IO.File.
13 remaining items
#74642 changed isolatedstorage path
#74642 Refactored and changed root only for mobile
#74642 minor changes
#74642 removed redundunt code
#74642 rename IsolatedStorageDirectoryName
#74642 change also in comments
#74642 changed IsolatedStorageDirectoryName for only mobile
#74642 done minor changes
#74642 made IsolatedStorageDirectoryName const
#74642 removed whitespaces
#74642 fix csproj for linux
akoeplinger commentedon Sep 28, 2022
This was fixed in main with #74642 and we have a backport PR open to fix it for .NET 7 with #76254
dtaylorus commentedon Sep 28, 2022
Fantastic. Thanks all!
[release/7.0] Fix isolated storage path on mobile (#76254)