I am trying to create instances of internal classes that are in the same assembly as the calling class. Unfortunately, this is not working for me. I’m using the following code snippet:
Assembly businessAssembly = this.GetType().Assembly;
var concreteValidator = businessAssembly.CreateInstance(t.NotificationType.ValidatorClassName, true,
BindingFlags.Default | BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic,
null,
new Object[] { t },
null,
null);
Note that t.NotificationType.ValidatorClassName is in the form Namespace.ClassName.
Shouldn’t that do the job? Where did I go wrong?
If the class is
publicinternal and the constructor is public, then theCreateInstancemethod is missing the public binding flag:Which would become: