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

Fix different generic parameters returning the same delegate #384

Merged

Conversation

DemoJameson
Copy link
Contributor

No description provided.

Copy link
Member

@tristanmcpherson tristanmcpherson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I find it funny we haven't run into this before, I'm guessing this wasn't introduced recently either?

@tristanmcpherson tristanmcpherson merged commit 9da3470 into risk-of-thunder:master Apr 10, 2022
@DemoJameson
Copy link
Contributor Author

DemoJameson commented Apr 10, 2022

it wasn't introduced recently, I tried reverting to the CastDelegate<T>() extension method from the forced casting, but it still doesn't work

        var person = new Person();
        Console.WriteLine(person.GetFieldValue<object>("name"));
        Console.WriteLine(person.GetFieldValue<string>("name"));
Unhandled Exception:
System.ArgumentException: method return type is incompatible
  at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, System.Boolean throwOnBindFailure, System.Boolean allowClosed) [0x00069] in <32116eccb94d4ed685ca661d98e36637>:0
  at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method) [0x00000] in <32116eccb94d4ed685ca661d98e36637>:0
  at System.Reflection.RuntimeMethodInfo.CreateDelegate (System.Type delegateType, System.Object target) [0x00000] in <32116eccb94d4ed685ca661d98e36637>:0
  at MonoMod.Utils.Extensions.CastDelegate (System.Delegate source, System.Type type) [0x00023] in <c03b1f3aed35488e835d604b9374363f>:0
  at MonoMod.Utils.Extensions.CastDelegate[T] (System.Delegate source) [0x00000] in <c03b1f3aed35488e835d604b9374363f>:0
  at R2API.Utils.Reflection.GetFieldGetDelegate[TReturn] (System.Reflection.FieldInfo field) [0x0002a] in <c76c8ea2ea7548b8b89f3e6f45901cd4>:0
  at R2API.Utils.Reflection.GetFieldValue[TReturn] (System.Object instance, System.String fieldName) [0x00011] in <c76c8ea2ea7548b8b89f3e6f45901cd4>:0

@tristanmcpherson
Copy link
Member

it wasn't introduced recently, I tried reverting to the CastDelegate<T>() extension method from the forced casting, but it still doesn't work

        var person = new Person();
        Console.WriteLine(person.GetFieldValue<object>("name"));
        Console.WriteLine(person.GetFieldValue<string>("name"));
Unhandled Exception:
System.ArgumentException: method return type is incompatible
  at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, System.Boolean throwOnBindFailure, System.Boolean allowClosed) [0x00069] in <32116eccb94d4ed685ca661d98e36637>:0
  at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method) [0x00000] in <32116eccb94d4ed685ca661d98e36637>:0
  at System.Reflection.RuntimeMethodInfo.CreateDelegate (System.Type delegateType, System.Object target) [0x00000] in <32116eccb94d4ed685ca661d98e36637>:0
  at MonoMod.Utils.Extensions.CastDelegate (System.Delegate source, System.Type type) [0x00023] in <c03b1f3aed35488e835d604b9374363f>:0
  at MonoMod.Utils.Extensions.CastDelegate[T] (System.Delegate source) [0x00000] in <c03b1f3aed35488e835d604b9374363f>:0
  at R2API.Utils.Reflection.GetFieldGetDelegate[TReturn] (System.Reflection.FieldInfo field) [0x0002a] in <c76c8ea2ea7548b8b89f3e6f45901cd4>:0
  at R2API.Utils.Reflection.GetFieldValue[TReturn] (System.Object instance, System.String fieldName) [0x00011] in <c76c8ea2ea7548b8b89f3e6f45901cd4>:0

Guess it wasn't a very highly used feature in that scenario then, good catch

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

Successfully merging this pull request may close these issues.

None yet

2 participants