From 69f252ab2828ac174329c2bf83aa2b338efd9fa7 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 29 Jun 2021 09:18:51 -0400 Subject: [PATCH 1/4] [mono] Don't call Assembly.CodeBase directly in RuntimeAssembly.GetName It's marked as not available in single file apps. Call the underlying get_code_base icall. Fixes https://github.com/dotnet/runtime/issues/54835 --- .../src/System/Reflection/RuntimeAssembly.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs index 5fb9e07417464..907f306280bf6 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs @@ -253,9 +253,7 @@ private static void AddPublicNestedTypes(Type type, List types, List Date: Wed, 30 Jun 2021 11:22:12 -0400 Subject: [PATCH 2/4] [icall] Use MonoImage:filename for RuntimeAssembly.get_code_base For bundled asssemblies in single file scenarios, RuntimeAssembly.CodeBase will be null, matching CoreCLR. --- src/mono/mono/metadata/icall.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index 84fc4df27c1b2..d725b1c3b5fd1 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -4462,12 +4462,18 @@ MonoStringHandle ves_icall_System_Reflection_RuntimeAssembly_get_code_base (MonoReflectionAssemblyHandle assembly, MonoError *error) { MonoAssembly *mass = MONO_HANDLE_GETVAL (assembly, assembly); - gchar *absolute; - if (g_path_is_absolute (mass->image->name)) { - absolute = g_strdup (mass->image->name); + /* return NULL for bundled assemblies in single-file scenarios */ + const char* filename = m_image_get_filename (mass->image); + + if (!filename) + return NULL_HANDLE_STRING; + + gchar *absolute; + if (g_path_is_absolute (filename)) { + absolute = g_strdup (filename); } else { - absolute = g_build_filename (mass->basedir, mass->image->name, (const char*)NULL); + absolute = g_build_filename (mass->basedir, filename, (const char*)NULL); } mono_icall_make_platform_path (absolute); From f6741c666e7279cfa75cd1f134544e3396e97e84 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 30 Jun 2021 12:42:45 -0400 Subject: [PATCH 3/4] Fixup after rebase on origin/main --- .../src/System/Reflection/RuntimeAssembly.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs index 907f306280bf6..21ac12509e6be 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs @@ -253,7 +253,7 @@ private static void AddPublicNestedTypes(Type type, List types, List Date: Tue, 6 Jul 2021 10:24:26 -0400 Subject: [PATCH 4/4] disable codebase test on wasm --- src/libraries/System.Reflection/tests/AssemblyTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Reflection/tests/AssemblyTests.cs b/src/libraries/System.Reflection/tests/AssemblyTests.cs index 0732615ec9e02..6c5c8c2bb320b 100644 --- a/src/libraries/System.Reflection/tests/AssemblyTests.cs +++ b/src/libraries/System.Reflection/tests/AssemblyTests.cs @@ -510,7 +510,7 @@ public void Location_ExecutingAssembly_IsNotNull() } #pragma warning disable SYSLIB0012 - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] // single file public void CodeBase() { Assert.NotEmpty(Helpers.ExecutingAssembly.CodeBase);