Skip to content

Commit beeafa0

Browse files
authored
Fix IsolatedStorage initialization on Android (#56534)
Android doesn't set an entry assembly so we need to handle that case. Fixes #52332
1 parent eb0b60e commit beeafa0

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,35 +46,37 @@ internal static void GetDefaultIdentityAndHash(out object identity, out string h
4646
// by pulling directly from EntryAssembly.
4747
//
4848
// Note that it is possible that there won't be an EntryAssembly, which is something the .NET Framework doesn't
49-
// have to deal with and shouldn't be likely on .NET Core due to a single AppDomain. Without Evidence
50-
// to pull from we'd have to dig into the use case to try and find a reasonable solution should we
51-
// run into this in the wild.
49+
// have to deal with and isn't likely on .NET Core due to a single AppDomain. The exception is Android which
50+
// doesn't set an EntryAssembly.
5251

5352
Assembly? assembly = Assembly.GetEntryAssembly();
53+
string? location = null;
5454

55-
if (assembly == null)
56-
throw new IsolatedStorageException(SR.IsolatedStorage_Init);
57-
58-
AssemblyName assemblyName = assembly.GetName();
59-
60-
hash = IdentityHelper.GetNormalizedStrongNameHash(assemblyName)!;
61-
if (hash != null)
55+
if (assembly != null)
6256
{
63-
hash = "StrongName" + separator + hash;
64-
identity = assemblyName;
65-
}
66-
else
67-
{
68-
string? location = assembly.Location;
69-
// In case of SingleFile deployment, Assembly.Location is empty.
70-
if (location == string.Empty)
71-
location = Environment.ProcessPath;
72-
if (string.IsNullOrEmpty(location))
73-
throw new IsolatedStorageException(SR.IsolatedStorage_Init);
74-
Uri locationUri = new Uri(location);
75-
hash = "Url" + separator + IdentityHelper.GetNormalizedUriHash(locationUri);
76-
identity = locationUri;
57+
AssemblyName assemblyName = assembly.GetName();
58+
59+
hash = IdentityHelper.GetNormalizedStrongNameHash(assemblyName)!;
60+
if (hash != null)
61+
{
62+
hash = "StrongName" + separator + hash;
63+
identity = assemblyName;
64+
return;
65+
}
66+
else
67+
{
68+
location = assembly.Location;
69+
}
7770
}
71+
72+
// In case of SingleFile deployment, Assembly.Location is empty. On Android there is no entry assembly.
73+
if (string.IsNullOrEmpty(location))
74+
location = Environment.ProcessPath;
75+
if (string.IsNullOrEmpty(location))
76+
throw new IsolatedStorageException(SR.IsolatedStorage_Init);
77+
Uri locationUri = new Uri(location);
78+
hash = "Url" + separator + IdentityHelper.GetNormalizedUriHash(locationUri);
79+
identity = locationUri;
7880
}
7981

8082
internal static string GetRandomDirectory(string rootDirectory, IsolatedStorageScope scope)

0 commit comments

Comments
 (0)