From 69db9b18cbe052a21c1b8e5db780b071ac31ecf4 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 25 Jan 2025 22:26:03 +0300 Subject: [PATCH 1/3] [dotnet] Address some build warnings --- dotnet/src/webdriver/Cookie.cs | 2 +- dotnet/src/webdriver/CookieJar.cs | 2 +- dotnet/src/webdriver/Internal/FileUtilities.cs | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/dotnet/src/webdriver/Cookie.cs b/dotnet/src/webdriver/Cookie.cs index b15dca6d196fe..dac30e0522629 100644 --- a/dotnet/src/webdriver/Cookie.cs +++ b/dotnet/src/webdriver/Cookie.cs @@ -277,7 +277,7 @@ public static Cookie FromDictionary(Dictionary rawCookie) { if (rawCookie == null) { - throw new ArgumentNullException(nameof(rawCookie), "Dictionary cannot be null"); + throw new ArgumentNullException(nameof(rawCookie)); } string name = rawCookie["name"].ToString(); diff --git a/dotnet/src/webdriver/CookieJar.cs b/dotnet/src/webdriver/CookieJar.cs index 470d81653cdff..32674b24c4e43 100644 --- a/dotnet/src/webdriver/CookieJar.cs +++ b/dotnet/src/webdriver/CookieJar.cs @@ -127,7 +127,7 @@ public void DeleteAllCookies() { var rawCookie = driver.InternalExecute(DriverCommand.GetCookie, new() { { "name", name } }).Value; - return Cookie.FromDictionary((Dictionary)rawCookie); + return Cookie.FromDictionary((Dictionary)rawCookie!); } catch (NoSuchCookieException) { diff --git a/dotnet/src/webdriver/Internal/FileUtilities.cs b/dotnet/src/webdriver/Internal/FileUtilities.cs index d288a58e5f296..4e6be99b463e9 100644 --- a/dotnet/src/webdriver/Internal/FileUtilities.cs +++ b/dotnet/src/webdriver/Internal/FileUtilities.cs @@ -188,11 +188,18 @@ public static string GetCurrentDirectory() string currentDirectory = location!; + // If we're shadow copying, get the directory from the codebase instead if (AppDomain.CurrentDomain.ShadowCopyFiles) { - Uri uri = new Uri(executingAssembly.CodeBase); - currentDirectory = Path.GetDirectoryName(uri.LocalPath)!; +#pragma warning disable SYSLIB0012 // Type or member is obsolete + var codeBase = executingAssembly.CodeBase; +#pragma warning restore SYSLIB0012 // Type or member is obsolete + + if (codeBase is not null) + { + currentDirectory = Path.GetDirectoryName(codeBase)!; + } } return currentDirectory; From d7a984cdf23c6449ae5e2a8b1c6472eec8304781 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 25 Jan 2025 22:42:23 +0300 Subject: [PATCH 2/3] Remove CodeBase per target framework --- dotnet/src/webdriver/Internal/FileUtilities.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dotnet/src/webdriver/Internal/FileUtilities.cs b/dotnet/src/webdriver/Internal/FileUtilities.cs index 4e6be99b463e9..7d47e2c3a99a1 100644 --- a/dotnet/src/webdriver/Internal/FileUtilities.cs +++ b/dotnet/src/webdriver/Internal/FileUtilities.cs @@ -187,20 +187,18 @@ public static string GetCurrentDirectory() } string currentDirectory = location!; - - +#if !NET8_0_OR_GREATER // If we're shadow copying, get the directory from the codebase instead if (AppDomain.CurrentDomain.ShadowCopyFiles) { -#pragma warning disable SYSLIB0012 // Type or member is obsolete var codeBase = executingAssembly.CodeBase; -#pragma warning restore SYSLIB0012 // Type or member is obsolete if (codeBase is not null) { currentDirectory = Path.GetDirectoryName(codeBase)!; } } +#endif return currentDirectory; } From 11ec9e191ff27b4964e68ffc12c42249c5f04adc Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 25 Jan 2025 22:44:03 +0300 Subject: [PATCH 3/3] Update FileUtilities.cs --- dotnet/src/webdriver/Internal/FileUtilities.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/Internal/FileUtilities.cs b/dotnet/src/webdriver/Internal/FileUtilities.cs index 7d47e2c3a99a1..ff23a34a1cf86 100644 --- a/dotnet/src/webdriver/Internal/FileUtilities.cs +++ b/dotnet/src/webdriver/Internal/FileUtilities.cs @@ -187,6 +187,7 @@ public static string GetCurrentDirectory() } string currentDirectory = location!; + #if !NET8_0_OR_GREATER // If we're shadow copying, get the directory from the codebase instead if (AppDomain.CurrentDomain.ShadowCopyFiles) @@ -195,7 +196,7 @@ public static string GetCurrentDirectory() if (codeBase is not null) { - currentDirectory = Path.GetDirectoryName(codeBase)!; + currentDirectory = Path.GetDirectoryName(codeBase); } } #endif