-2

I have a defined a dictionary and when try to store the Activator.CreateInstance, its says Object reference not set to an instance of an object.

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);

Any ideas how can I cache the instances for later use.

Thanks,

1 Answers1

0

The problem is that you never instantiate your Dictionary

I can't know what your "implementation" is but here just assign a new instance of the dictionary and you are good to go

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