MissingMethodException: Default constructor not found

Solutions:
– Use IL2CPP build instead of Mono2x
– Or, set Stripping Level: Disabled (any other stripping level didn’t work)

Probably the cause was changing Api Compatibility Level from “.net 2.0 Subset” into “.net 2.0”..

Instead of using Activator.CreateInstance, you could also use reflection to instantiate your states. This has 2 benefits:

  • You can implement some logic to find the correct constructor based on parameter types (and you'll get more descriptive errors if you mess something up)
  • It performs a little better

Here's how you'd do that:

var ctor = typeof(T).GetConstructor(new []{typeof(GameObject)})
currentState = ctor.Invoke(new object[]{this.gameObject}) as T;

项目使用的版本是 .net Framework 4.7,编译通过,运行时报错
Method not found
刚开始以为是dll版本引入不一致,查了一下都是一样的
后来公司主管看到问题后,说时需要安装一下4.7.1,4.7.2
之前只安装了4.7.1
安装之后,果然可以运行了
因为微软在小版本上打了补丁,所以必须要安装一下。
————————————————
版权声明:本文为优快云博主「stoneLSL」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/stoneLSL/article/details/88018390

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值