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

关于Assembly.GetExecutingAssembly #48

Closed
AlanLiu90 opened this issue Feb 23, 2023 · 2 comments
Closed

关于Assembly.GetExecutingAssembly #48

AlanLiu90 opened this issue Feb 23, 2023 · 2 comments

Comments

@AlanLiu90
Copy link
Contributor

环境

Unity 2020.3.33
il2cpp_plus 2020-1.0
hybridclr 1.0
hybridclr_unity 1.0
OS+Build Windows 10 64 bit
project hybridclr_trial

问题

Assembly.GetExecutingAssembly()返回了错误的assembly,看文档说是IL2CPP的bug。但是我测试了在AOT中调用是正常的:

string TestInMain()
{
	return Assembly.GetExecutingAssembly().FullName;
}

生成的C++代码:

// System.String LoadDll::TestInMain()
IL2CPP_EXTERN_C IL2CPP_METHOD_ATTR String_t* LoadDll_TestInMain_m453A6AE1AE65CDB8E6502B9C4C6E71559A18B7D9 (LoadDll_tF4302664700CA4FCBC0471B8C95631AE6442BC68 * __this, const RuntimeMethod* method)
{
	static bool s_Il2CppMethodInitialized;
	if (!s_Il2CppMethodInitialized)
	{
		il2cpp_codegen_initialize_runtime_metadata((uintptr_t*)&LoadDll_TestInMain_m453A6AE1AE65CDB8E6502B9C4C6E71559A18B7D9_RuntimeMethod_var);
		s_Il2CppMethodInitialized = true;
	}
	{
		// return Assembly.GetExecutingAssembly().FullName;
		Assembly_t * L_0;
		L_0 = il2cpp_codegen_get_executing_assembly(LoadDll_TestInMain_m453A6AE1AE65CDB8E6502B9C4C6E71559A18B7D9_RuntimeMethod_var);
		NullCheck(L_0);
		String_t* L_1;
		L_1 = VirtFuncInvoker0< String_t* >::Invoke(12 /* System.String System.Reflection.Assembly::get_FullName() */, L_0);
		return L_1;
	}
}

看起来IL2CPP做了特殊处理,并不会去调用Assembly.GetExecutingAssembly()生成的C++函数Assembly_GetExecutingAssembly_m990AB6145F5E80CC3CC8912043DC18497C2369EB

// System.Reflection.Assembly System.Reflection.Assembly::GetExecutingAssembly()
IL2CPP_EXTERN_C IL2CPP_METHOD_ATTR Assembly_t * Assembly_GetExecutingAssembly_m990AB6145F5E80CC3CC8912043DC18497C2369EB (const RuntimeMethod* method)
{
	static bool s_Il2CppMethodInitialized;
	if (!s_Il2CppMethodInitialized)
	{
		il2cpp_codegen_initialize_runtime_metadata((uintptr_t*)&Assembly_GetExecutingAssembly_m990AB6145F5E80CC3CC8912043DC18497C2369EB_RuntimeMethod_var);
		s_Il2CppMethodInitialized = true;
	}
	return il2cpp_codegen_get_executing_assembly(Assembly_GetExecutingAssembly_m990AB6145F5E80CC3CC8912043DC18497C2369EB_RuntimeMethod_var);
}

HybridCLR的解释版本执行之所以有问题,就是因为调用了这个函数。

是否考虑做下特殊处理解决这个问题?比如新增一个InstinctInstrument,专门用于处理Assembly.GetExecutingAssembly()

@pirunxi
Copy link
Contributor

pirunxi commented Feb 23, 2023

合理,我们马上修复它。

@pirunxi
Copy link
Contributor

pirunxi commented Feb 23, 2023

感谢,已解决。需要手动安装最新hybridclr代码。

@pirunxi pirunxi closed this as completed Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants