Skip to content

Unable to patch methods located inside the GlobalType (aka. <Module>) #235

Description

@zsr2531

Describe the bug

When a method is resolved inside the GlobalType (this is only possible via Module.ResolveMethod(int MDToken)) its DeclaringType property is null and when an attempt is made to patch the method, a NRE will get thrown in this function: GeneralExtensions.FullDescription(this MethodBase method)

To Reproduce

  1. Resolve a method via its metadata token that is inside <Module> (or also known as the globaltype)
  2. Try to apply any patch to it

Expected behavior
The patch gets applied

Screenshot
Image

Runtime environment:

  • OS: Windows 10, 64bit
  • .NET version 4.8
  • Harmony version 1.2.0.1

Activity

  1. pardeike commented on Jan 16, 2020

    @pardeike
    Owner

    Thanks for the analysis. I am in no means an expert in C# and the concept of a GlobalType is totally new to me. I guess I have to look over my use of DeclaringType in the whole project. Thanks.

  2. pardeike commented on Jan 25, 2020

    @pardeike
    Owner

    Fixed in latest master. Please verify.

  3. added a commit that references this issue on Feb 1, 2024
    b306aae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions