【Unity升级问题处理】Unity5.4.x升级到Unity2019遇到的坑-System.MissingMethodException
原文链接:https://blog.csdn.net/u013294596/article/details/121565482
System.Reflection.BindingFlags
ReadSelectedTable Error = System.MissingMethodException: TABLE.xxx.rows Due to: Attempted to access a missing member.
at System.RuntimeType.InvokeMember (System.String name, System.Reflection.BindingFlags bindingFlags, System.Reflection.Binder binder, System.Object target, System.Object[] providedArgs, System.Reflection.ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, System.String[] namedParams) [0x0070c] in <567df3e0919241ba98db88bec4c6696f>:0
at System.Type.InvokeMember (System.String name, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object target, System.Object[] args) [0x00000] in <567df3e0919241ba98db88bec4c6696f>:0
————————————————
官方解释:为了获取返回值,必须指定 BindingFlags.Instance 或 BindingFlags.Static。
指定 BindingFlags.Public 可在搜索中包含公共成员。
指定 BindingFlags.NonPublic 可在搜索中包含非公共成员(即私有成员和受保护的成员)。
指定 BindingFlags.FlattenHierarchy 可包含层次结构上的静态成员。
下列 BindingFlags 修饰符标志可用于更改搜索的执行方式:
BindingFlags.IgnoreCase,表示忽略 name 的大小写。
BindingFlags.DeclaredOnly,仅搜索 Type 上声明的成员,而不搜索被简单继承的成员。
可以使用下列 BindingFlags 调用标志表示要对成员采取的操作:
CreateInstance,表示调用构造函数。忽略 name。对其他调用标志无效。
InvokeMethod,表示调用方法,而不调用构造函数或类型初始值设定项。对 SetField 或 SetProperty 无效。
GetField,表示获取字段值。对 SetField 无效。
SetField,表示设置字段值。对 GetField 无效。
GetProperty,表示获取属性。对 SetProperty 无效。
SetProperty 表示设置属性。对 GetProperty 无效。
BindingFlags.Instance:对象实例
BindingFlags.Static:静态成员
BindingFlags.Public:指可在搜索中包含公共成员
BindingFlags.NonPublic:指可在搜索中包含非公共成员(即私有成员和受保护的成员)
BindingFlags.FlattenHierarchy:指可包含层次结构上的静态成员
BindingFlags.IgnoreCase:表示忽略 name 的大小写
BindingFlags.DeclaredOnly:仅搜索 Type 上声明的成员,而不搜索被简单继承的成员
BindingFlags.CreateInstance:表示调用构造函数。忽略 name。对其他调用标志无效
Unity5.4.x版本
var rowsData = arrayType.InvokeMember("rows", BindingFlags.Public | BindingFlags.GetProperty , null, arrayData, null);
tableRows = (rowsData as ICollection).GetEnumerator();
解决方法:
Unity2019版本
var rowsData = arrayType.InvokeMember("rows", BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.Instance, null, arrayData, null);
tableRows = (rowsData as ICollection).GetEnumerator();
————————————————
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构