Skip to content

Commit 3d37577

Browse files
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).
1 parent 895d60b commit 3d37577

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

mono/metadata/reflection.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,13 +2655,12 @@ reflection_bind_generic_method_parameters (MonoMethod *method, MonoArrayHandle t
26552655
tmp_context.method_inst = ginst;
26562656

26572657
inflated = mono_class_inflate_generic_method_checked (method, &tmp_context, error);
2658-
mono_error_assert_ok (error);
26592658

2660-
if (!mono_verifier_is_method_valid_generic_instantiation (inflated)) {
2659+
if (error || !inflated || !mono_verifier_is_method_valid_generic_instantiation (inflated)) {
26612660
#if ENABLE_NETCORE
26622661
mono_error_set_argument (error, NULL, "Invalid generic arguments");
26632662
#else
2664-
mono_error_set_argument (error, "typeArguments", "Invalid generic arguments");
2663+
mono_error_set_argument (error, NULL, "Invalid generic arguments");
26652664
#endif
26662665
return NULL;
26672666
}

0 commit comments

Comments
 (0)