From ebd12bece442a02ee413b3b2eeed7ef533011b2e Mon Sep 17 00:00:00 2001 From: Scott Ferguson Date: Wed, 18 Jun 2025 08:52:21 -0400 Subject: [PATCH] Remove Assert in Method.MakeGeneric on Invalid Args The call to mono_class_inflate_generic_method_checked will set error when there are invalid types (e.g. typeof(void)/typeof(int*)) passed in. This should not be an assert, we should all to the "Invalid generic arguments" message below. This does loose the error returned by mono_class_inflate_generic_method_checked but that error isn't user friendly. It would report be something like: "MVAR 1 cannot be expanded with type 0x1" We can just report the more readable error to the user. Note I also had to remove the "typeArguments" message from the error. When this error is freed Mono will attempt to deallocate that value, but since it's not a allocated value our allocator will crash (In Unity we replace Mono's allocators with our own). --- mono/metadata/reflection.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mono/metadata/reflection.c b/mono/metadata/reflection.c index 814794bbe982..037ee4ed2bc8 100644 --- a/mono/metadata/reflection.c +++ b/mono/metadata/reflection.c @@ -2655,13 +2655,12 @@ reflection_bind_generic_method_parameters (MonoMethod *method, MonoArrayHandle t tmp_context.method_inst = ginst; inflated = mono_class_inflate_generic_method_checked (method, &tmp_context, error); - mono_error_assert_ok (error); - if (!mono_verifier_is_method_valid_generic_instantiation (inflated)) { + if (!is_ok(error) || !inflated || !mono_verifier_is_method_valid_generic_instantiation (inflated)) { #if ENABLE_NETCORE mono_error_set_argument (error, NULL, "Invalid generic arguments"); #else - mono_error_set_argument (error, "typeArguments", "Invalid generic arguments"); + mono_error_set_argument (error, NULL, "Invalid generic arguments"); #endif return NULL; }