mardi 18 août 2015

Exception with invoking static method in Abstract Class Using Reflection

Unable to solve this issue and desperately need help. My project is calling a dll with below class. I need to use the static method using reflection but unable to make it work due to an exception "Object reference not set to an instance of an object"

namespace Binit.Core.Database
{

public abstract class DbFormat
{
    public static DbFormat Create();
}
}

Below code works

Binit.Core.Database.DbFormat format;
format = Binit.Core.Database.DbFormat.Create();

Below code using reflection fails

Assembly CoreDatabaseAssembly = Assembly.LoadFrom(Path.Combine(APath, @"Binit.Core.Database.dll"));
Type typDbFormatClass = CoreDatabaseAssembly.GetType("Binit.Core.Database.DbFormat");
MethodInfo createFormatMethod = typDbFormatClass.GetMethod("Create", BindingFlags.Static | BindingFlags.Public, null, new Type[] { }, null);
object objDbFormat = createFormatMethod.Invoke(null, null);

Exception:

Inner Exception Shows Object reference not set to an instance of an object.

InnerException null

Stacktrace

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[]   arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at AB.INIT.stringToValue(String valueInUnits, String dimension, String sourceUnit, String destinationUnit)





Aucun commentaire:

Enregistrer un commentaire