I wanted to dynamically load classes in C#. I remember in Java we used Class.forname("String") , so after googling I found out that we could use Activator.CreateInstance in C# . I cannot figure out what my assembly name would be here. Any suggestions ?
object obj = Activator.CreateInstance("MyAssembly","namespaceA.SomeClassName");
It’s simply the name of the assembly. That might be the same as the namespace, but it might not. For example, the
System.Linq.Enumerableclass is in theSystem.Coreassembly (inSystem.Core.dll).If the target assembly is a framework one, look at the documentation.
If it’s one that’s under your control, you should know the assembly name – it’s part of the project properties.