![](/img/trans.png)
[英]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.