Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call generic method with out parameter throws NullReferenceException without Flags.ExactBinding #16

Open
markjerz opened this issue Dec 16, 2020 · 0 comments

Comments

@markjerz
Copy link

I added the following method to Host in GenericTest:

public bool TryGet<T1, T2>(T2 obj1, out T1 obj2)
{
    obj2 = default;
    return true;
}

If I DO NOT include the Flags as below then it throws a NullReferenceException in MemberFilter when it attempts to call SubString on the name variable inside if( ignoreParameterModifiers && parameterType.IsByRef ). This is because the parameterType.FullName is null as the parameterType is generic.

[TestMethod]
public void Test_invoke_instance_generic_out()
{
    var target = typeof(Host).CreateInstance();
    var parameters = new object[] {1, null};
    var result = (bool)target.CallMethod(new[] {typeof(string), typeof(int)}, "TryGet",
                new[] {typeof(int), typeof(string).MakeByRefType()}, Flags.ExactBinding | Flags.InstancePublicDeclaredOnly, parameters);
    Assert.IsTrue(result);
    Assert.AreEqual(null, parameters[1]);
}

To work around this current problem, as I've done here, you must specify Flags.ExactBinding which then skips that particular bit of code.

Apologies, for not providing a PR with a failing test - I just had time to figure out a workaround and to then write it here so that somebody might fix in the future (or find the workaround!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant