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

Add a clear exception when trying to patch a target with unset generic arguments #51

Open
ghorsington opened this issue Jul 29, 2022 · 0 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@ghorsington
Copy link
Contributor

ghorsington commented Jul 29, 2022

When trying to patch methods like

  • Foo<T>.Method
  • Foo.Method<T>

patching fails with a somewhat cryptic error like

HarmonyLib.HarmonyException: IL Compile Error (unknown location) ---> HarmonyLib.HarmonyException: IL Compile Error (unknown location) ---> System.NotSupportedException: Specified method is not supported.
  at MonoMod.Utils.MMReflectionImporter.ImportGenericParameter (System.Type type, Mono.Cecil.IGenericParameterProvider context) [0x0008f] in <6733e342b5b549bba815373898724469>:0
  at MonoMod.Utils.MMReflectionImporter._ImportReference (System.Type type, Mono.Cecil.IGenericParameterProvider context, MonoMod.Utils.MMReflectionImporter+GenericImportKind importKind) [0x00130] in <6733e342b5b549bba815373898724469>:0
  at MonoMod.Utils.MMReflectionImporter._ImportGenericInstance (System.Type type, Mono.Cecil.IGenericParameterProvider context, Mono.Cecil.TypeReference typeRef) [0x0001c] in <6733e342b5b549bba815373898724469>:0
  at MonoMod.Utils.MMReflectionImporter._ImportReference (System.Type type, Mono.Cecil.IGenericParameterProvider context, MonoMod.Utils.MMReflectionImporter+GenericImportKind importKind) [0x00122] in <6733e342b5b549bba815373898724469>:0
  at MonoMod.Utils.MMReflectionImporter.ImportReference (System.Type type, Mono.Cecil.IGenericParameterProvider context) [0x00000] in <6733e342b5b549bba815373898724469>:0

Instead of letting the invalid target propagate to MonoMod, it's better to fail early with a clear message like

Generic methods cannot be patched. Assign the generic parameters (e.g. Foo<int> instead of Foo<T>).

and don't let patching proceed further.

@ghorsington ghorsington added bug Something isn't working enhancement New feature or request labels Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant