Skip to content

Remove Assert in Method.MakeGeneric on Invalid Args #2153

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

Open
wants to merge 1 commit into
base: unity-main
Choose a base branch
from

Conversation

scott-ferguson-unity
Copy link
Collaborator

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

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

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 remove-assert-on-invalid-method-generic-args branch from b890ca9 to 3d37577 Compare June 18, 2025 13:12
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.

3 participants