Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Activator.CreateInstance(assemblyType)使用c返回null#_C#_Reflection - Fatal编程技术网

C# Activator.CreateInstance(assemblyType)使用c返回null#

C# Activator.CreateInstance(assemblyType)使用c返回null#,c#,reflection,C#,Reflection,我们需要动态加载dll。因此,我使用了Activator.CreateInstance(assemblyType)c#代码,但它返回null。如果CreateInstance遇到抛出的问题,您能正常帮助我吗。然而,如果你再往下看,我们可以发现: 该方法为可为null的实例返回null 我想你可能选得早,而且类型不匹配: var o = Activator.CreateInstance(typeof(X)); var x = o as X; // not null var

我们需要动态加载dll。因此,我使用了Activator.CreateInstance(assemblyType)c#代码,但它返回null。如果
CreateInstance
遇到抛出的问题,您能正常帮助我吗。然而,如果你再往下看,我们可以发现:

该方法为可为null的实例返回null


我想你可能选得早,而且类型不匹配:

   var o = Activator.CreateInstance(typeof(X));

   var x = o as X; // not null 

   var y = o as Y; // null 

您能提供一些代码片段吗?您确定它返回null并且不会抛出吗?假设
assemblyType
类型
:它是什么类型?某些类型在其默认值形式下(比如:
int?
YourStruct?
等)将框设为null,我们无法帮助您进行如此模糊的描述。请张贴一些你正在做的代码。最好使用.IProtocolPluginLibrary.ihttpprotocol plugin=Activator.CreateInstance(assemblyType)作为IProtocolPluginLibrary.ihttpprotocol;