From b7b0666e7993428fc7eaa831615b43f75b040f69 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Wed, 3 Jul 2024 23:52:35 -0600 Subject: [PATCH] fix invalid Uri error when running in a Single file application (#201) fallback to AppContext.BaseDirectory if Assembly.Location is null or empty when attempting to determine the location of the icu.net assembly. Assembly.Location will be an empty string when publishing SingleFile. --- source/icu.net/NativeMethods/NativeMethods.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/icu.net/NativeMethods/NativeMethods.cs b/source/icu.net/NativeMethods/NativeMethods.cs index 3d091fb5..cc6ab483 100644 --- a/source/icu.net/NativeMethods/NativeMethods.cs +++ b/source/icu.net/NativeMethods/NativeMethods.cs @@ -176,6 +176,12 @@ internal static string DirectoryOfThisAssembly #endif #if NET var managedPath = currentAssembly.Location; + // If the application is published as a single file, Assembly.Location will be an empty string. + // Per the warning https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file/warnings/il3000 we should use AppContext.BaseDirectory instead. + if (string.IsNullOrEmpty(managedPath)) + { + managedPath = AppContext.BaseDirectory; + } #else var managedPath = currentAssembly.CodeBase ?? currentAssembly.Location; #endif