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
安装之后,果然可以运行了
因为微软在小版本上打了补丁,所以必须要安装一下。
————————————————
版权声明:本文为CSDN博主「stoneLSL」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/stoneLSL/article/details/88018390

上一篇:.NET5 在docker上启动失败


下一篇:python实现链表