I had a generic method that I'd like to invoke, but it throws the exception below:
Object reference not set to an instance of an object.
It's in fact the GetMethod(...) who equals to null. But I can't find where I did wrong cause I had a very similar function in another class. This is the code simple:
Class DatabaseSyncronizor
{
...
internal void SyncronizeAll()
{
for(int i=0;i<MyList.Count();i++)
{
Type type=Type.GetType(MyModelClass);
typeof(DatabaseSyncronizor).GetMethod("Synchronize",BindingFlags.NonPublic|BindingFlags.Instance).MakeGenericMethod(type).Invoke(this, null);
}
}
private void Syncronize<T>() where T :class,IDate
{
IGenericService<T> service = new GenericService<T>(new UnitOfWorkFactory(_connectionString));
...
}
}
Thank you for you help!
Regards, Léona
Your method is called Syncronize not Synchronize.
Try this
typeof(DatabaseSyncronizor).GetMethod("Syncronize",BindingFlags.NonPublic|BindingFlags.Instance)
.MakeGenericMethod(type).Invoke(this, null);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.