在我的反射代码中,我的通用代码部分遇到了问题。特别是当我使用字符串时。
var oVal = (object)"Test";
var oType = oVal.GetType();
var sz = Activator.CreateInstance(oType, oVal);
例外
An unhandled exception of type 'System.MissingMethodException' occurred in mscorlib.dll
Additional information: Constructor on type 'System.String' not found.
我出于测试目的尝试了这个,它也出现在这个单衬里
var sz = Activator.CreateInstance("".GetType(), "Test");
本来我写的
var sz = Activator.CreateInstance("".GetType());
但我得到这个错误
Additional information: No parameterless constructor defined for this object.
如何使用反射创建字符串?