Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Don't call Assembly.CodeBase directly in RuntimeAssembly.GetName #54895

Merged
merged 4 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libraries/System.Reflection/tests/AssemblyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ private static void AddPublicNestedTypes(Type type, List<Type> types, List<Excep

public override AssemblyName GetName(bool copiedName)
{
#pragma warning disable IL3002 // Suppressing for now. See https://github.com/dotnet/runtime/issues/54835
return AssemblyName.Create(_mono_assembly, CodeBase);
#pragma warning restore IL3002
return AssemblyName.Create(_mono_assembly, get_code_base (this));
}

[RequiresUnreferencedCode("Types might be removed")]
Expand Down
14 changes: 10 additions & 4 deletions src/mono/mono/metadata/icall.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down