Skip to content

Android: IsolatedStorageFile path changes #83231

Description

@Filastian

Description

The IsolatedStorageFile.GetUserStoreForApplication() call returns an object that has different paths depending on the build:

  • Xamarin.Android returns an object that has a root folder at /data/user/0/{packageName}/files/.config/.isolated-storage;
  • .NET 7 returns an object that has a root folder at /data/user/0/{packageName}/files/.isolated-storage/{hash}/{hash}/AppFiles/.

This creates problems using the file when upgrading the application to .NET 7, as the file cannot be used in an IsolatedStorageFileStream and all data is lost.

I saw that a similar problem existed for iOS in #74642 and has been fixed, one behaviour on Android remains the same.

Reproduction Steps

  1. Run the app on Xamarin.Android and create the file via IsolatedStorageFileStream;
  2. Note that the file was created along the same path;
  3. Migrate the project to .NET 7;
  4. Run the project and try to retrieve the file created in the previous version;
  5. Note that the file will not be found because the store file has a different path.

Code example:

using (var file = IsolatedStorageFile.GetUserStoreForApplication())
{
if (file.FileExists("test"))
{
using var stream = new IsolatedStorageFileStream(
"test",
FileMode.Create,
FileAccess.Read,
file
);
// Do something here
}
}

Expected behavior

The file will be found along the same path

Actual behavior

The file of the previous version will not be found. A new file is created on the new path

Regression?

Yes, this is a regression. The file system path for IsolatedStorageFile was consistent in .NET Framework applications

Known Workarounds

I don't know a workaround for getting the old file using IsolatedStorageFileStream. The only thing, we can replace IsolatedStorageFileStream with FileStream and manually specify the file path.

Code example:

var filePath = AppContext.BaseDirectory + "/.config/.isolated-storage/test";
if (File.Exists(filePath))
{
using var stream = new FileStream(StorageFilePath, FileMode.Open, FileAccess.Read);
// Do something here
}

Configuration

.NET SDK:
Version: 7.0.200
Commit: 534117727b

Runtime Environment:
OS Name: Mac OS X
OS Version: 13.0
OS Platform: Darwin
RID: osx.13-x64
Base Path: /usr/local/share/dotnet/sdk/7.0.200/

Host:
Version: 7.0.3
Architecture: x64
Commit: 0a2bda1

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