Skip to content

[6000.3] Remove Assert in Method.MakeGeneric on Invalid Args #2154

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

Conversation

scott-ferguson-unity
Copy link
Collaborator

@scott-ferguson-unity scott-ferguson-unity commented Jun 24, 2025

This is a backport of #2161

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).

Upstream issue: dotnet/runtime#71339
Upstream PR: dotnet/runtime#116788

  • Should this pull request have release notes?
    • Yes
    • No
  • Do these changes need to be back ported?
    • Yes
    • No
  • Do these changes need to be upstreamed to mono/mono or dotnet/runtime repositories?
    • Yes
    • No

Reviewers: please consider these questions as well! ❤️

Release notes

Fixed UUM-109251 @scott-ferguson-unity:
Mono: Prevent crash when Method.MakeGenericMethod is called with invalid generic argument types

@scott-ferguson-unity scott-ferguson-unity changed the title Remove Assert in Method.MakeGeneric on Invalid Args [6000.3= Remove Assert in Method.MakeGeneric on Invalid Args Jun 24, 2025
@scott-ferguson-unity scott-ferguson-unity changed the title [6000.3= Remove Assert in Method.MakeGeneric on Invalid Args [6000.3] Remove Assert in Method.MakeGeneric on Invalid Args Jun 24, 2025
@scott-ferguson-unity scott-ferguson-unity force-pushed the 6000.3/remove-assert-on-invalid-method-generic-args branch from 6d95ffa to 1be6ad5 Compare July 28, 2025 12:41
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).
@scott-ferguson-unity scott-ferguson-unity force-pushed the 6000.3/remove-assert-on-invalid-method-generic-args branch from 1be6ad5 to ebd12be Compare July 30, 2025 12:16
@scott-ferguson-unity scott-ferguson-unity merged commit 89b4d72 into unity-6000.3-mbe Jul 30, 2025
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants