Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: IsolatedStorageFile path changes #83231

Closed
Filastian opened this issue Mar 9, 2023 · 3 comments · Fixed by #83380
Closed

Android: IsolatedStorageFile path changes #83231

Filastian opened this issue Mar 9, 2023 · 3 comments · Fixed by #83380
Assignees
Milestone

Comments

@Filastian
Copy link

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

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Mar 9, 2023
@ghost
Copy link

ghost commented Mar 9, 2023

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

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

Author: Filastian
Assignees: -
Labels:

area-System.IO, untriaged

Milestone: -

@ghost
Copy link

ghost commented Mar 9, 2023

Tagging subscribers to 'arch-android': @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

Issue Details

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

Author: Filastian
Assignees: -
Labels:

area-System.IO, os-android, untriaged

Milestone: -

@steveisok steveisok removed the untriaged New issue has not been triaged by the area owner label Mar 9, 2023
@steveisok steveisok added this to the 8.0.0 milestone Mar 9, 2023
@steveisok
Copy link
Member

@mkhamoyan please take a look and if it makes sense, adapt the ios changes you made for android.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Mar 14, 2023
@marek-safar marek-safar modified the milestones: 8.0.0, 7.0.x Mar 20, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label May 11, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jun 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants