From 3f672978390156beb5c285cf88a46a900501ea56 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Mon, 29 Jun 2020 08:07:25 -0400 Subject: [PATCH 1/6] Return / in AppContext.BaseDirectory for wasm --- .../System.Private.CoreLib.Shared.projitems | 2 ++ .../src/System/AppContext.Browser.cs | 16 ++++++++++++++ .../src/System/AppContext.UnixOrWindows.cs | 21 +++++++++++++++++++ .../src/System/AppContext.cs | 11 ++-------- 4 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 src/libraries/System.Private.CoreLib/src/System/AppContext.Browser.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/AppContext.UnixOrWindows.cs diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index fcd3398d24589e..1d961560fd99a7 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -44,6 +44,8 @@ + + diff --git a/src/libraries/System.Private.CoreLib/src/System/AppContext.Browser.cs b/src/libraries/System.Private.CoreLib/src/System/AppContext.Browser.cs new file mode 100644 index 00000000000000..c97cdc4bf76709 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/AppContext.Browser.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System +{ + public static partial class AppContext + { + private static string GetBaseDirectoryCore() + { + // GetEntryAssembly().Location returns an empty string for wasm + // Until that can be easily changed, work around the problem here. + return "/"; + } + } +} \ No newline at end of file diff --git a/src/libraries/System.Private.CoreLib/src/System/AppContext.UnixOrWindows.cs b/src/libraries/System.Private.CoreLib/src/System/AppContext.UnixOrWindows.cs new file mode 100644 index 00000000000000..855c1dc327828f --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/AppContext.UnixOrWindows.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.IO; +using System.Reflection; + +namespace System +{ + public static partial class AppContext + { + private static string GetBaseDirectoryCore() + { + // Fallback path for hosts that do not set APP_CONTEXT_BASE_DIRECTORY explicitly + string? directory = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location); + if (directory != null && !Path.EndsInDirectorySeparator(directory)) + directory += PathInternal.DirectorySeparatorCharAsString; + return directory ?? string.Empty; + } + } +} \ No newline at end of file diff --git a/src/libraries/System.Private.CoreLib/src/System/AppContext.cs b/src/libraries/System.Private.CoreLib/src/System/AppContext.cs index 90735669641622..049ac4701919c0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/AppContext.cs +++ b/src/libraries/System.Private.CoreLib/src/System/AppContext.cs @@ -36,7 +36,9 @@ public static partial class AppContext throw new ArgumentNullException(nameof(name)); if (s_dataStore == null) + { return null; + } object? data; lock (s_dataStore) @@ -142,15 +144,6 @@ internal static unsafe void Setup(char** pNames, char** pValues, int count) s_dataStore.Add(new string(pNames[i]), new string(pValues[i])); } } - - private static string GetBaseDirectoryCore() - { - // Fallback path for hosts that do not set APP_CONTEXT_BASE_DIRECTORY explicitly - string? directory = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location); - if (directory != null && !Path.EndsInDirectorySeparator(directory)) - directory += PathInternal.DirectorySeparatorCharAsString; - return directory ?? string.Empty; - } #endif } } From d7960c6c5a6c9f53892be1fade47f7e92d92065f Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Thu, 2 Jul 2020 15:29:52 -0400 Subject: [PATCH 2/6] Adjust AppContext.BaseDirectory to return "/" for wasm because GetEntryAssembly().Location returns an empty string. This change also enables most of the Microsoft.Extensions.* tests with the exception of DependencyModel and Hosting. --- .../tests/XmlConfigurationTest.cs | 3 ++- .../tests/AssemblyInfo.cs | 8 ++++++++ .../tests/UnitTests/AssemblyInfo.cs | 8 ++++++++ src/libraries/tests.proj | 8 -------- 4 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 src/libraries/Microsoft.Extensions.DependencyModel/tests/AssemblyInfo.cs create mode 100644 src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/AssemblyInfo.cs diff --git a/src/libraries/Microsoft.Extensions.Configuration.Xml/tests/XmlConfigurationTest.cs b/src/libraries/Microsoft.Extensions.Configuration.Xml/tests/XmlConfigurationTest.cs index 5e34cdc0ad4dab..b3e8e20401591e 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Xml/tests/XmlConfigurationTest.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.Xml/tests/XmlConfigurationTest.cs @@ -432,7 +432,8 @@ public void XmlConfiguration_Does_Not_Throw_On_Optional_Configuration() var config = new ConfigurationBuilder().AddXmlFile("NotExistingConfig.xml", optional: true).Build(); } - [ConditionalFact] + [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] [FrameworkSkipCondition(RuntimeFrameworks.Mono)] public void LoadKeyValuePairsFromValidEncryptedXml() { diff --git a/src/libraries/Microsoft.Extensions.DependencyModel/tests/AssemblyInfo.cs b/src/libraries/Microsoft.Extensions.DependencyModel/tests/AssemblyInfo.cs new file mode 100644 index 00000000000000..01510ab2d8b719 --- /dev/null +++ b/src/libraries/Microsoft.Extensions.DependencyModel/tests/AssemblyInfo.cs @@ -0,0 +1,8 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using Xunit; + +[assembly: ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] \ No newline at end of file diff --git a/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/AssemblyInfo.cs b/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/AssemblyInfo.cs new file mode 100644 index 00000000000000..01510ab2d8b719 --- /dev/null +++ b/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/AssemblyInfo.cs @@ -0,0 +1,8 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using Xunit; + +[assembly: ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] \ No newline at end of file diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index f5b47857a2c20a..2610a2937e76ae 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -31,14 +31,6 @@ - - - - - - - - From 3f7e5a79403778def08c1a2c039974448c74e0cb Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Thu, 2 Jul 2020 15:40:22 -0400 Subject: [PATCH 3/6] Format tweak --- src/libraries/System.Private.CoreLib/src/System/AppContext.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/AppContext.cs b/src/libraries/System.Private.CoreLib/src/System/AppContext.cs index 049ac4701919c0..f809eba655dd19 100644 --- a/src/libraries/System.Private.CoreLib/src/System/AppContext.cs +++ b/src/libraries/System.Private.CoreLib/src/System/AppContext.cs @@ -36,9 +36,7 @@ public static partial class AppContext throw new ArgumentNullException(nameof(name)); if (s_dataStore == null) - { return null; - } object? data; lock (s_dataStore) From db4159e52d6e88ce2d0136b315857539425ed130 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Mon, 6 Jul 2020 08:30:12 -0400 Subject: [PATCH 4/6] Skip test that depends on FSW --- .../tests/FunctionalTests/ConfigurationTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/Microsoft.Extensions.Configuration/tests/FunctionalTests/ConfigurationTests.cs b/src/libraries/Microsoft.Extensions.Configuration/tests/FunctionalTests/ConfigurationTests.cs index 70878278bef596..7e8940e57e3891 100644 --- a/src/libraries/Microsoft.Extensions.Configuration/tests/FunctionalTests/ConfigurationTests.cs +++ b/src/libraries/Microsoft.Extensions.Configuration/tests/FunctionalTests/ConfigurationTests.cs @@ -902,6 +902,7 @@ public void GetDefaultBasePathForSources() [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/34580", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)] + [SkipOnMono("System.IO.FileSystem.Watcher is not supported on wasm", TestPlatforms.Browser)] public void CanEnumerateProviders() { var config = CreateBuilder() From f6ad87e6bd9504740a274ebb42d948753782ad92 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Mon, 6 Jul 2020 16:02:56 -0400 Subject: [PATCH 5/6] Feedback --- .../src/System.Private.CoreLib.Shared.projitems | 2 +- .../{AppContext.UnixOrWindows.cs => AppContext.AnyOS.cs} | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) rename src/libraries/System.Private.CoreLib/src/System/{AppContext.UnixOrWindows.cs => AppContext.AnyOS.cs} (78%) diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 1d961560fd99a7..8de0e0c72c96f3 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -45,7 +45,7 @@ - + diff --git a/src/libraries/System.Private.CoreLib/src/System/AppContext.UnixOrWindows.cs b/src/libraries/System.Private.CoreLib/src/System/AppContext.AnyOS.cs similarity index 78% rename from src/libraries/System.Private.CoreLib/src/System/AppContext.UnixOrWindows.cs rename to src/libraries/System.Private.CoreLib/src/System/AppContext.AnyOS.cs index 855c1dc327828f..fdb6b451c91bbd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/AppContext.UnixOrWindows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/AppContext.AnyOS.cs @@ -13,9 +13,14 @@ private static string GetBaseDirectoryCore() { // Fallback path for hosts that do not set APP_CONTEXT_BASE_DIRECTORY explicitly string? directory = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location); - if (directory != null && !Path.EndsInDirectorySeparator(directory)) + + if (directory == null) + return string.Empty; + + if (!Path.EndsInDirectorySeparator(directory)) directory += PathInternal.DirectorySeparatorCharAsString; - return directory ?? string.Empty; + + return directory; } } } \ No newline at end of file From 3dcbda4bf4390d5eeee5495f5a2a5edbdad04359 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Mon, 6 Jul 2020 16:26:08 -0400 Subject: [PATCH 6/6] Whitespace :-) --- .../System.Private.CoreLib/src/System/AppContext.AnyOS.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/AppContext.AnyOS.cs b/src/libraries/System.Private.CoreLib/src/System/AppContext.AnyOS.cs index fdb6b451c91bbd..f9d97fec05bf8f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/AppContext.AnyOS.cs +++ b/src/libraries/System.Private.CoreLib/src/System/AppContext.AnyOS.cs @@ -16,7 +16,7 @@ private static string GetBaseDirectoryCore() if (directory == null) return string.Empty; - + if (!Path.EndsInDirectorySeparator(directory)) directory += PathInternal.DirectorySeparatorCharAsString;