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

ILRT不支持静态构造 #254

Closed
leiguoqiang opened this issue Jan 24, 2019 · 1 comment
Closed

ILRT不支持静态构造 #254

leiguoqiang opened this issue Jan 24, 2019 · 1 comment

Comments

@leiguoqiang
Copy link

leiguoqiang commented Jan 24, 2019

热更代码中含有静态构造生产CLR绑定会报错

static ListController() { var type = typeof(AA); var flag = BindingFlags.NonPublic | BindingFlags.Instance; fileInfo = type.GetField("mItemPrefabDataList", flag); itemDict = type.GetField("mItemPoolDict", flag); itemList = type.GetField("mItemPoolList", flag); recycleAllItem = type.GetMethod("RecycleAllItem", flag); adjustAnchorInfo = type.GetMethod("AdjustAnchor", flag); adjustPivotInfo = type.GetMethod("AdjustPivot", flag); }

ArgumentNullException: Value cannot be null.
Parameter name: types
System.Type.GetMethod (System.String name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Reflection.CallingConventions callConvention, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) (at :0)
ILRuntime.Reflection.ILRuntimeWrapperType.GetMethodImpl (System.String name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Reflection.CallingConventions callConvention, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) (at Assets/Scripts/ILRT/ILRuntime/Reflection/ILRuntimeWrapperType.cs:117)
System.Type.GetMethod (System.String name, System.Reflection.BindingFlags bindingAttr) (at :0)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at :0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at :0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at :0)
ILRuntime.CLR.Method.CLRMethod.Invoke (ILRuntime.Runtime.Intepreter.ILIntepreter intepreter, ILRuntime.Runtime.Stack.StackObject* esp, System.Collections.Generic.IList`1[T] mStack, System.Boolean isNewObj) (at Assets/Scripts/ILRT/ILRuntime/CLR/Method/CLRMethod.cs:316)
ILRuntime.Runtime.Intepreter.ILIntepreter.Execute (ILRuntime.CLR.Method.ILMethod method, ILRuntime.Runtime.Stack.StackObject* esp, System.Boolean& unhandledException) (at Assets/Scripts/ILRT/ILRuntime/Runtime/Intepreter/ILIntepreter.cs:1797)
Rethrow as ILRuntimeException: Exception has been thrown by the target of an invocation.
IL_0049: callvirt System.Reflection.MethodInfo System.Type::GetMethod(System.String,System.Reflection.BindingFlags)
Common.ListController..cctor()

@fatfatson
Copy link

是啊,我也遇到了类似情况:
image

似乎是分析过程中,静态构造代码会被实际运行,如果某个静态字段的初值依赖于实际运行结果,那肯定在分析模式下会出错了。

liiir1985 added a commit that referenced this issue Apr 2, 2020
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

3 participants