Skip to content

Remove Assert in Method.MakeGeneric on Invalid Arg #116788

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
Contributor

@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 fall 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"

Instead report the more general/readable error to the user.

Fix: #71339.

Repro:

    internal class Program
    {
        static void Main(string[] args)
        {
            try
            {
                typeof(Program)!.GetMethod(nameof(Get))!.MakeGenericMethod(typeof(void));
            }
            catch ( Exception ex)
            {
                Console.WriteLine(ex);
            }
        }

        public T Get<T>() => default;
    }

Result Before:

* Assertion at \src\mono\mono\metadata\reflection.c:2731, condition `is_ok (error)' not met, function:reflection_bind_generic_method_parameters, MVAR 0 cannot be expanded with type 0x1
CRASH!

Result After:

System.ArgumentException: Invalid generic arguments

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 18, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 18, 2025
@scott-ferguson-unity scott-ferguson-unity force-pushed the fix-make-generic-method-assert-on-invalid-args-fix-71339 branch from 9752615 to 3768e58 Compare June 27, 2025 12:14
@teo-tsirpanis teo-tsirpanis added area-VM-reflection-mono Reflection issues specific to MonoVM and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jun 28, 2025
Copy link
Member

@steveisok steveisok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scott-ferguson-unity can you get rid of the files in the out dir? Other than that, this LGTM.

@scott-ferguson-unity
Copy link
Contributor Author

@dotnet-policy-service agree company="Unity Technologies"

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, it should fall to the "Invalid generic
arguments" message below.   This does lose 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" Instead report the more readable error to the user.

Fix: 71339
@scott-ferguson-unity scott-ferguson-unity force-pushed the fix-make-generic-method-assert-on-invalid-args-fix-71339 branch from 3768e58 to c4ed2c4 Compare July 22, 2025 11:16
@scott-ferguson-unity
Copy link
Contributor Author

@scott-ferguson-unity can you get rid of the files in the out dir? Other than that, this LGTM.

@steveisok Sorry about those files, clearly wasn't paying attention! Should be good now.

@steveisok
Copy link
Member

/ba-g Unclear wasm failure

@steveisok steveisok merged commit be1ef91 into dotnet:main Aug 18, 2025
64 of 70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-VM-reflection-mono Reflection issues specific to MonoVM community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid type for MakeGenericMethod is crashing the runtime
3 participants