From 6e8bd5bcf4283cf69f7cf3fc9089fc4ca46ef42e Mon Sep 17 00:00:00 2001 From: Adeel Date: Sun, 20 Sep 2020 11:16:35 +0300 Subject: [PATCH] Fix SingleFile regression in IsolatedStorageFile --- .../System/IO/IsolatedStorage/Helper.Win32Unix.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs index 33e611115fa28..0822a9525590a 100644 --- a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs @@ -51,14 +51,13 @@ internal static void GetDefaultIdentityAndHash(out object identity, out string h Assembly? assembly = Assembly.GetEntryAssembly(); if (assembly == null) + { throw new IsolatedStorageException(SR.IsolatedStorage_Init); + } AssemblyName assemblyName = assembly.GetName(); -#pragma warning disable SYSLIB0012 - Uri codeBase = new Uri(assembly.CodeBase!); -#pragma warning restore SYSLIB0012 - hash = IdentityHelper.GetNormalizedStrongNameHash(assemblyName)!; + if (hash != null) { hash = "StrongName" + separator + hash; @@ -66,8 +65,11 @@ internal static void GetDefaultIdentityAndHash(out object identity, out string h } else { - hash = "Url" + separator + IdentityHelper.GetNormalizedUriHash(codeBase); - identity = codeBase; + // in case of SingleFile, Location.Length returns 0. + string fileName = assembly.Location.Length == 0 ? assemblyName.Name! : Path.GetFileName(assembly.Location); + Uri assemblyPath = new Uri(Path.Combine(AppContext.BaseDirectory, fileName)); + hash = "Url" + separator + IdentityHelper.GetNormalizedUriHash(assemblyPath); + identity = assemblyPath; } }