无法加载文件或程序集
问题描述:
我正在创建Silverlight应用程序运行时的动态类型的通用集合。我的代码:无法加载文件或程序集
Type listType =
Type.GetType("System.Collections.ObjectModel.ObservableCollection`1[["
+ type.AssemblyQualifiedName
+ "]], System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
true);
type
是Type
类型的变量。该类型正在运行时创建。在该代码行我有错误:
Could not load file or assembly ', Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
我该如何解决该错误?
答
使用MakeGenericType
代替:
Activator.CreateInstance(typeof(ObservableCollection<>).MakeGenericType(type));