dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.91k stars 4.63k forks source link

IsolatedStorage doesn't work from Single-File application in 5.0 #42265

Closed ericstj closed 3 years ago

ericstj commented 3 years ago

Description

Create an app using IsolatedStorage. Publish as single file.

try
{
    var store = IsolatedStorageFile.GetUserStoreForApplication();
    var file = store.CreateFile("test.txt");
    Console.WriteLine(file.Name);
}
catch (Exception e)
{
    Console.WriteLine(e);
}

Configuration

.NET 5.0 Single file publish Tested on win-x64 but should be present everywhere.

Regression?

Yes. Worked in 3.1

Regressed by https://github.com/dotnet/runtime/pull/40974

Related https://github.com/dotnet/runtime/issues/42161

ghost commented 3 years ago

Tagging subscribers to this area: @agocke See info in area-owners.md if you want to be subscribed.

agocke commented 3 years ago

Mitigated by https://github.com/dotnet/runtime/pull/42435

am11 commented 3 years ago

Mitigated by #42435

I am not seeing any difference in behavior. The above repro still throws NotSupportedException with today's (two hours old) master branch and 5.0 latest preview.

agocke commented 3 years ago

Including passing the flag IncludeAllContentForSelfExtract?

am11 commented 3 years ago

Yup, I tried publishing with a fresh local build of master: dotnet publish -r osx-x64 -p:IncludeAllContentForSelfExtract=True -p:PublishSingleFile=True -c Release

throws:

System.NotSupportedException: CodeBase is not supported on assemblies loaded from a single-file bundle.
   at System.Reflection.RuntimeAssembly.get_CodeBase()
   at System.IO.IsolatedStorage.Helper.GetDefaultIdentityAndHash(Object& identity, String& hash, Char separator)
   at System.IO.IsolatedStorage.IsolatedStorage.InitStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType)
   at System.IO.IsolatedStorage.IsolatedStorageFile..ctor(IsolatedStorageScope scope)
   at System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication()
   at isolated.Program.Main(String[] args)

revision:

$ strings /Users/am11/projects/runtime_base/.dotnet2/dotnet 2>&1 | grep Commit
@(#)Version 42.42.42.42424 @Commit: 30e643e2f2433055d6ed433af38a925ee657d4ad
agocke commented 3 years ago

Looks like the 6.0 installer builds have been blocked for quite a while now. Testing locally, looks like CodeBase works appropriately in 5.0 RTM.

am11 commented 3 years ago

Confirmed. With 5.0.100-rtm.20506.2 (runtime: 30e643e2f2433055d6ed433af38a925ee657d4a), it does not throw NotSupportedException. If there is no further action required, shall we close this issue and #42306?

carlossanlop commented 3 years ago

Confirmed. With 5.0.100-rtm.20506.2 (runtime: 30e643e), it does not throw NotSupportedException. If there is no further action required, shall we close this issue and #42306?

@ericstj do we still want to merge the PR #42306 to main? Would we be interested in backporting it to 5.0 at some point? I ask because @agocke mentioned that #42435 was a mitigation, but not the actual fix.

ericstj commented 3 years ago

Yes merging to master is fine. We can service to 5.0 if anyone is blocked and can’t use the workaround.

kostasvl commented 3 years ago

Hi. This occurs for me on 5.0.203. It's a WPF app, published via ClickOnce, single file, self-contained.

System.NotSupportedException: CodeBase is not supported on assemblies loaded from a single-file bundle. at System.Reflection.RuntimeAssembly.get_CodeBase() at System.IO.IsolatedStorage.Helper.GetDefaultIdentityAndHash(Object& identity, String& hash, Char separator) at System.IO.IsolatedStorage.IsolatedStorage.InitStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType) at System.IO.IsolatedStorage.IsolatedStorageFile..ctor(IsolatedStorageScope scope) at System.IO.IsolatedStorage.IsolatedStorageFile.GetMachineStoreForApplication() at MyApp.App.Application_Startup(Object sender, StartupEventArgs e)

agocke commented 3 years ago

Should be resolved in 6.0