Mono/C#: Fix load hook not called for some assemblies on domain reload
(cherry picked from commit f5510262bc
)
This commit is contained in:
parent
a98d44f654
commit
8cdcb410e0
|
@ -277,12 +277,25 @@ no_pdb:
|
|||
|
||||
#endif
|
||||
|
||||
bool need_manual_load_hook = mono_image_get_assembly(image) != nullptr; // Re-using an existing image with an assembly loaded
|
||||
|
||||
status = MONO_IMAGE_OK;
|
||||
|
||||
MonoAssembly *assembly = mono_assembly_load_from_full(image, image_filename.utf8().get_data(), &status, p_refonly);
|
||||
|
||||
ERR_FAIL_COND_V_MSG(status != MONO_IMAGE_OK || !assembly, NULL, "Failed to load assembly for image");
|
||||
|
||||
if (need_manual_load_hook) {
|
||||
// For some reason if an assembly survived domain reloading (maybe because it's referenced somewhere else),
|
||||
// the mono internal search hook don't detect it, yet mono_image_open_from_data_with_name re-uses the image
|
||||
// and assembly, and mono_assembly_load_from_full doesn't call the load hook. We need to call it manually.
|
||||
String name = String::utf8(mono_assembly_name_get_name(mono_assembly_get_name(assembly)));
|
||||
bool has_extension = name.ends_with(".dll") || name.ends_with(".exe");
|
||||
GDMonoAssembly *loaded_asm = GDMono::get_singleton()->get_loaded_assembly(has_extension ? name.get_basename() : name);
|
||||
if (!loaded_asm)
|
||||
assembly_load_hook(assembly, nullptr);
|
||||
}
|
||||
|
||||
// Decrement refcount which was previously incremented by mono_image_open_from_data_with_name
|
||||
mono_image_close(image);
|
||||
|
||||
|
|
Loading…
Reference in New Issue