Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.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# 无法获取类型为.GetType(字符串)的LinkedList`T的类型_C#_.net_Reflection - Fatal编程技术网

C# 无法获取类型为.GetType(字符串)的LinkedList`T的类型

C# 无法获取类型为.GetType(字符串)的LinkedList`T的类型,c#,.net,reflection,C#,.net,Reflection,我可以通过以下方式获取列表、字典等的类型信息: Type.GetType("System.Collections.Generic.List`1[System.String]") Type.GetType("System.Collections.Generic.Dictionary`2[System.String,System.String[]]") 但无法获取链接列表的类型信息: 检查LinkedList的程序集 使用.NET Standart 2.0.3.尝试为System.Collecti

我可以通过以下方式获取
列表
字典
等的类型信息:

Type.GetType("System.Collections.Generic.List`1[System.String]")
Type.GetType("System.Collections.Generic.Dictionary`2[System.String,System.String[]]")
但无法获取
链接列表的类型信息

检查
LinkedList的程序集


使用.NET Standart 2.0.3.

尝试为
System.Collections.Generic.LinkedList
1`类型指定完全限定的程序集名称

var type=type.GetType(“System.Collections.Generic.LinkedList`1[System.String],System,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”);
或者只使用程序集名称

type=type.GetType(“System.Collections.Generic.LinkedList`1[System.String],System”);
mscorlib.dll
的一部分,是否是
System.dll

你几乎就在这里

Type.GetType(“System.Collections.Generic.LinkedList`1[[System.String,mscorlib,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089]])也返回NULL

但是您已经为泛型类型参数指定了完全限定名,它是
System.String
type,而不是
LinkedList

显然,这是因为
List
是在自动被探测的
mscorlib.dll
中定义的,而
LinkedList
是在
System.dll
中定义的(来自GAC)

因此,在动态加载程序集时,必须显式表示程序集名称:

Type.GetType("System.Collections.Generic.LinkedList`1, System")
从:

如果类型位于当前执行的程序集中或Mscorlib.dll中, 提供由其命名空间限定的类型名就足够了


OP:请注意,
LinkedList
位于.NET Framework上的系统程序集中,但它位于.NET Core上的System.Collections程序集中。看见如果对程序集名称进行硬编码,则将绑定到特定的实现。如果你可以使用
typeof(LinkedList)
来代替,你应该这样做。你绝对是对的@madreflection。在编译时获取类型信息很简单,但我的挑战是在运行时从用户定义的字符串中获取类型信息。PS:我试图安装
系统。集合
软件包,但在您发表评论之前失败。谢谢,你的评论对我也有帮助。
typeof(LinkedList<decimal>).Assembly
System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Type.GetType("System.Collections.Generic.LinkedList`1, System")