【发布时间】:2015-11-18 21:16:43
【问题描述】:
我正在尝试在我的 CoreCLR 应用程序中创建一个类的实例,但是当我调用 Activator.CreateInstance 时,我得到一个 System.MissingMethodException 说它在它试图创建的类上找不到构造函数。该类确实有一个构造函数。我做错了什么?
该项目仅针对 dnxcore50。
这是代码:
using System;
namespace MyNamespace
{
public class Program
{
public void Main(string[] args)
{
Activator.CreateInstance(typeof (MyClass), true);
}
}
public class MyClass
{
public MyClass() { }
}
}
这是个例外:
System.MissingMethodException was unhandled by user code
HResult=-2146233069
Message=Constructor on type 'MyNamespace.MyClass' not found.
Source=mscorlib
StackTrace:
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at MyNamespace.Program.Main(String[] args) in C:\projects\coreclrplayground\InvokeMember\src\InvokeMember\Program.cs:line 9
InnerException:
【问题讨论】:
标签: c# reflection asp.net-core dnx coreclr