2016-02-19 52 views
-2

我有一个定义的字典,当尝试存储的Activator.CreateInstance,其表示未将对象引用设置到对象的实例。Activator.CreateInstance存储在一个字典

public static Dictionary<string, object> AssemblyInstances { get; set; } 
var typeA = Assembly.LoadFile(assemblyPath).GetTypes()[0]; 
var instance = Activator.CreateInstance(typeA) as ISomeInterface; 
AssemblyInstances.Add("Implementation", instance); 

任何想法如何缓存实例供以后使用。

感谢,

回答

0

的问题是,你永远不会实例化你的字典

我不知道你的“执行”是,但这里只是指定字典的新实例,你是好去

public static Dictionary<string, object> AssemblyInstances { get; set; } = new Dictionary<string, object>();