I am trying to call a static method of a static class via reflection but getting exception Non-static method requires a target
My class in .net standard 2.1 library is
namespace MyNameSpace
{
public static class MyClass
{
public static string DecryptData(string input)
{
return ....;
}
}
}
My code for calling the class in .net core application is
private string GetDetails(string data)
{
string content = null;
Type dllType = null;
var asm = Assembly.LoadFrom(fileName);
foreach (var t in asm.GetTypes())
{
if (t.IsClass && t.IsPublic)
{
dllType = t;
break;
}
}
if (dllType != null)// class successfully found
{
MethodInfo staticMethodInfo = dllType.GetMethod("DecryptData");//method successfully found
var o = staticMethodInfo.Invoke(null, new object[] { data });//exception on this line
}
return content;
}
Aucun commentaire:
Enregistrer un commentaire