Skip to content

Commit

Permalink
[mono] Invoke AssemblyLoad hooks from RuntimeAssemblyBuilder:.ctor ()…
Browse files Browse the repository at this point in the history
… instead from native code. (#85307)

The call from native code is made before the manifest module was created, causing errors if the
hook tried to access Assembly.ManifestModule.

Fixes #84771.
  • Loading branch information
vargaz authored Apr 28, 2023
1 parent e6924ee commit 5cea3d6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,11 @@ private static void OnAssemblyLoad(RuntimeAssembly assembly)
return InvokeResolveEvent(AssemblyResolve, assembly, assemblyFullName);
}

internal static void InvokeAssemblyLoadEvent(Assembly assembly)
{
AssemblyLoad?.Invoke(AppDomain.CurrentDomain, new AssemblyLoadEventArgs(assembly));
}

[UnconditionalSuppressMessage("SingleFile", "IL3000: Avoid accessing Assembly file path when publishing as a single file",
Justification = "The code handles the Assembly.Location equals null")]
private static RuntimeAssembly? InvokeResolveEvent(ResolveEventHandler? eventHandler, RuntimeAssembly? assembly, string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ internal RuntimeAssemblyBuilder(AssemblyName n, AssemblyBuilderAccess access)
// Netcore only allows one module per assembly
manifest_module = new RuntimeModuleBuilder(this, "RefEmit_InMemoryManifestModule");
modules = new RuntimeModuleBuilder[] { manifest_module };

AssemblyLoadContext.InvokeAssemblyLoadEvent (this);
}

public override bool ReflectionOnly
Expand Down
4 changes: 4 additions & 0 deletions src/mono/mono/metadata/appdomain.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ mono_domain_fire_assembly_load_event (MonoDomain *domain, MonoAssembly *assembly
if (!method)
goto exit;

if (assembly->dynamic)
/* Called by RuntimeAssemblyBuilder:.ctor () after the manifest module has been created */
goto exit;

MonoReflectionAssemblyHandle assembly_handle;
assembly_handle = mono_assembly_get_object_handle (assembly, error);
goto_if_nok (error, exit);
Expand Down

0 comments on commit 5cea3d6

Please sign in to comment.