[英]C# Npgsql connection checker Exception Throw System.NullReferenceException 'Object reference not set to an instance of an object.'
[英]C# GetMethod throw exception: Object reference not set to an instance of an object
我有一個要調用的通用方法,但是它引發以下異常:
你調用的對象是空的。
實際上是GetMethod(...)等於null。 但是我找不到我做錯了什么地方,因為我在另一個類中有一個非常相似的功能。 這是簡單的代碼:
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));
...
}
}
謝謝你的幫助!
問候,萊昂納
您的方法稱為“同步不同步”。
嘗試這個
typeof(DatabaseSyncronizor).GetMethod("Syncronize",BindingFlags.NonPublic|BindingFlags.Instance)
.MakeGenericMethod(type).Invoke(this, null);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.