Closed
Description
Description
I am embadding monovm, I write a function mono_alc_load_assembly_with_partial_name
extend from mono_assembly_load_with_partial_name
with alc
argument
when call mono_image_open_from_data_alc
to load MonoImage
the mono_alc_from_gchandle
get the wrong MonoAssemblyLoadContext
value
Reproduction Steps
// I implemented AssemblyLoadContext:
public class PluginLoadContext : AssemblyLoadContext
{
public PluginLoadContext(string? name, bool isCollectible) : base(name, isCollectible)
{
}
protected override Assembly? Load(AssemblyName assemblyName)
{
return PluginLoader.LoadAssembly(assemblyName.Name);
}
}
// like mono_assembly_load_with_partial_name just pass our ALC, not use default alc
MonoAssembly*
mono_alc_load_assembly_with_partial_name (void* native_alc, const char *name, MonoImageOpenStatus *status)
{
MonoAssembly *result;
MONO_ENTER_GC_UNSAFE;
MonoImageOpenStatus def_status;
if (!status)
status = &def_status;
MonoAssemblyLoadContext* alc = (MonoAssemblyLoadContext*)native_alc;
if (!alc)
alc = mono_alc_get_default();
result = mono_assembly_load_with_partial_name_internal (name, alc, status);
MONO_EXIT_GC_UNSAFE;
return result;
}
// get MonoAssemblyLoadContext though `_nativeAssemblyLoadContext` field
// the internal call
MonoObject* ScriptingManager::LoadAssembly(MonoObject* alc, MonoString* assemblyName)
{
void* NativeALC = GetNativeALC(alc);
if (!NativeALC)
return nullptr;
MonoImageOpenStatus LoadStatus = MonoImageOpenStatus::MONO_IMAGE_OK;
const char* AssemblyName = mono_string_to_utf8(assemblyName);
MonoAssembly* Assembly = mono_alc_load_assembly_with_partial_name(NativeALC, AssemblyName, &LoadStatus);
mono_free((void*)AssemblyName);
return (MonoObject*)mono_assembly_get_object(mono_domain_get(), Assembly);
}
our code call step
// in c#
PluginLoaderContent alc = new PluginLoaderContent ("Engine", true);
// call internal call ScriptingManager::LoadAssembly
LoadAssembly(alc, "UnrealEngine");
the native stack variable
- new PluginLoaderContent create native ALC, and the alc native address is
0x000001c4bfdf51a0
-
in the
ScriptingManager::LoadAssembly
, we can see the MonoObject* alc and native alc value is correct.
Expected behavior
work correctly
Actual behavior
crash
Regression?
No response
Known Workarounds
No response
Configuration
build the latest version of release/6.0 branch
x64 windows desktop
Other information
no