Skip to content

IsolatedStorageFile.GetUserStoreForApplication path changes between Xamarin.iOS and .NET 6 builds on iOS #74642

Closed
@dtaylorus

Description

@dtaylorus

Description

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:

/var/mobile/Containers/Data/Application/<GUID>/Documents/IsolatedStorage/tz12rggn.q0z/hi51wlzn.hmf/Url.j1gfq4nxq1m4zfi31rjvtcuna3umf3fb/AppFiles/settings.txt
/var/mobile/Containers/Data/Application/<GUID>/Documents/IsolatedStorage/tz12rggn.q0z/hi51wlzn.hmf/Url.vb0fraupqrlwtvom530yjpnqlhlbggfc/AppFiles/settings.txt
/var/mobile/Containers/Data/Application/<GUID>/Documents/IsolatedStorage/tz12rggn.q0z/hi51wlzn.hmf/Url.az1iqc1z0lv42e3agh4zvg5aa5rbihzj/AppFiles/settings.txt
/var/mobile/Containers/Data/Application/<GUID>/Documents/IsolatedStorage/tz12rggn.q0z/hi51wlzn.hmf/Url.efra4nhzgkrws2l30v4hbayjiohm2ofj/AppFiles/settings.txt
...

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).

Configuration

.NET 6
iOS
ARM64

This issue is specific to .NET 6 on iOS

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions