jeudi 22 juin 2023

Type.InvokeMember not invoking method and not throwing

I have this method that invokes other methods by reflection:

public void InvokeInstanceMethod(string projectName, string typeName,
        string methodName, IDictionary<string, object> args, object instance)
{
    var assembly = GetAssembly(projectName);

    var type = GetType(projectName, typeName, assembly);

    type.InvokeMember(methodName, BindingFlags.InvokeMethod |
        BindingFlags.Public | BindingFlags.Instance, null, instance,
        args.Select(a => a.Value).ToArray(), null, null, args.Select(a => a.Key).ToArray());

}

Normally it works ok, but sometimes it just doesn't invoke the member and it doesn't throw, it simply continues execuction as if everything went fine, there is no pattern I can spot, for the same method sometimes it works, others it doesn't.

Anything wrong with my implementation?

https://learn.microsoft.com/en-us/dotnet/api/system.type.invokemember?view=netcore-3.1

Using dotnet Core 3.1





Aucun commentaire:

Enregistrer un commentaire