From 31c499d2acdc21f47ecc8e5e7562cf60ed061437 Mon Sep 17 00:00:00 2001 From: lindexi Date: Thu, 12 Aug 2021 22:08:34 +0800 Subject: [PATCH 1/2] Fix GetStreamCore in ContentFilePart The Application.ResourceAssembly.CodeBase is the string without escaped. See: - https://github.com/dotnet/wpf/issues/4781 - https://github.com/dotnet/wpf/pull/5004 - https://github.com/dotnet/wpf/pull/4799 --- .../MS/Internal/AppModel/ContentFilePart.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ContentFilePart.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ContentFilePart.cs index 02838d46d4f..0a2c5416b06 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ContentFilePart.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ContentFilePart.cs @@ -60,7 +60,7 @@ protected override Stream GetStreamCore(FileMode mode, FileAccess access) // File name will be a path relative to the applications directory. // - We do not want to use SiteOfOriginContainer.SiteOfOrigin because // for deployed files the files are deployed with the application. - Uri codeBase = GetEntryAssemblyLocation(); + string codeBase = GetEntryAssemblyLocation(); string assemblyName, assemblyVersion, assemblyKey; string filePath; @@ -73,8 +73,7 @@ protected override Stream GetStreamCore(FileMode mode, FileAccess access) BaseUriHelper.GetAssemblyNameAndPart(Uri, out filePath, out assemblyName, out assemblyVersion, out assemblyKey); // filePath should not have leading slash. GetAssemblyNameAndPart( ) can guarantee it. - Uri file = new Uri(codeBase, filePath); - _fullPath = file.LocalPath; + _fullPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(codeBase), filePath); } stream = CriticalOpenFile(_fullPath); @@ -103,15 +102,15 @@ protected override string GetContentTypeCore() #region Private Methods - private Uri GetEntryAssemblyLocation() + private string GetEntryAssemblyLocation() { - Uri entryLocation = null; + string entryLocation = null; try { - #pragma warning disable // Type or member is obsolete - entryLocation = new Uri(Application.ResourceAssembly.CodeBase); - #pragma warning restore // Type or member is obsolete + // We do not want to use Application.ResourceAssembly.CodeBase + // because it is obsolete. + entryLocation = Application.ResourceAssembly.Location; } catch (Exception ex) { From a71e6a09fd38f989b38818b07d2e734d6c0bb23c Mon Sep 17 00:00:00 2001 From: lindexi Date: Sun, 15 Aug 2021 09:20:36 +0800 Subject: [PATCH 2/2] Rename the variable and remove the unuse comment. --- .../MS/Internal/AppModel/ContentFilePart.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ContentFilePart.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ContentFilePart.cs index 0a2c5416b06..93148ec7489 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ContentFilePart.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ContentFilePart.cs @@ -60,7 +60,7 @@ protected override Stream GetStreamCore(FileMode mode, FileAccess access) // File name will be a path relative to the applications directory. // - We do not want to use SiteOfOriginContainer.SiteOfOrigin because // for deployed files the files are deployed with the application. - string codeBase = GetEntryAssemblyLocation(); + string location = GetEntryAssemblyLocation(); string assemblyName, assemblyVersion, assemblyKey; string filePath; @@ -73,7 +73,7 @@ protected override Stream GetStreamCore(FileMode mode, FileAccess access) BaseUriHelper.GetAssemblyNameAndPart(Uri, out filePath, out assemblyName, out assemblyVersion, out assemblyKey); // filePath should not have leading slash. GetAssemblyNameAndPart( ) can guarantee it. - _fullPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(codeBase), filePath); + _fullPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(location), filePath); } stream = CriticalOpenFile(_fullPath); @@ -108,8 +108,6 @@ private string GetEntryAssemblyLocation() try { - // We do not want to use Application.ResourceAssembly.CodeBase - // because it is obsolete. entryLocation = Application.ResourceAssembly.Location; } catch (Exception ex)