-
-
Notifications
You must be signed in to change notification settings - Fork 518
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
Unable to patch methods which DeclaringType is null #445
Comments
Can you please verify with master that the issue is solved and reopen it if it isn't? |
Ping @GeorgyPorgy |
I checked the behavior with the new changes and it seems some of the problems have already been fixed, but the patching has not yet ended successfully. The last line in the Harmony debug log reports : while in the application log the messages list is as follows : Runtime environment :
|
Right now, I can only guess the problem because I have no idea how to write a test for such a method. If you know a way to reference such a method in a test please let me know. |
Also the stacktrace indicates that your original method has some very unusual IL codes that trigger the InlineSignature parser. Could you tell me more about your original method and maybe list it’s IL code. Parsing inline IL is still new and not much tested either and has nothing to do with the method being without type. |
On further inspection, the stacktrace isn’t helpful because there are several casts to |
Thanks for your efforts, Andreas. The method IL code can be seen at the link below : The instruction list was generated with ILSpy. I will attempt to extract additional information with the help of the debugger and provide it as soon as possible. P.S. |
At this point it is unclear if it is at all possible to create the correct result from this calli due to my possible limitations in the c# reflection api. I spoke with @0x0ade and it looks like there might be a very convoluted way to support this but at this point it’s unclear if and who could implement this. It’s a rather difficult topic. |
Hello Andreas, https://www.codeproject.com/Articles/1244372/Reflecting-Within-a-Method-Body Would this article help us ? regards |
That article just shows the basics. Our code here handles this case already: Harmony/Harmony/Internal/MethodCopier.cs Line 381 in 3c4cd7f
It’s the parser that fails the case because it is more complicated than the article suggests. |
Describe the bug
When a target method is resolved via Module.ResolveMethod(int Token) its DeclaringType property is null and future attempt to patch the method triggers "System.NullReferenceException: Object reference not set to an instance of an object" at CreateDynamicMethod(MethodBase original, String suffix, Boolean debug)
In fact, the problem described is similar to that described in an already closed ticket. : "Unable to patch methods located inside the GlobalType (aka. ) #235 "
To Reproduce
Steps to reproduce the behavior:
ERROR - System.NullReferenceException: Object reference not set to an instance of an object.
at HarmonyLib.MethodPatcher.CreateDynamicMethod(MethodBase original, String suffix, Boolean debug)
at HarmonyLib.MethodPatcher..ctor(MethodBase original, MethodBase source, List
1 prefixes, List
1 postfixes, List1 transpilers, List
1 finalizers, Boolean debug)at HarmonyLib.PatchFunctions.UpdateWrapper(MethodBase original, PatchInfo patchInfo)
at HarmonyLib.PatchProcessor.Patch()
Expected behavior
The patch gets applied.
Runtime environment (please complete the following information):
The text was updated successfully, but these errors were encountered: