We upgraded from .NET 3.5 to .NET 4.0 and now System.Refelection.Assembly.CreateInstance does not seem to work. Who else has this problem? Is there any way to fix this? The following is an example of how we load the assembly. It returns a null value. No exceptions. This is a .NET assembly registered in the GAC. This is not a COM object.
Assembly assembly = Assembly.LoadWithPartialName("AssemblyName");
object instance = assembly.CreateInstance("Namespace.Class",
false,
BindingFlags.CreateInstance,
null,
null, null, null);
I narrowed down the cause of the problem. My class A that I'm trying to create inherits from class B. Class B is defined as an open abstract class B. Class B contains most of the logic with one abstract method that defines class A. Similarly, I have another class C that inherits from class B, which has a different definition for the method. Basically refactoring for sharing common logic. This worked in .NET 3.5, but in .NET 4.0 I finally narrowed down the exception to be "{" Cannot create an abstract class. "}".
public abstract class A
{
public string InvokeUI()
{
DisplayUI();
}
protected abstract void DisplayUI();
}
public class B : A
{
protected override DisplayUI()
{
Some logic;
}
}
Tammy source
share