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

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

Conversation

scott-ferguson-unity
Copy link

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.

Repo:

    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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community-contribution Indicates that the PR has been added by a community member needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid type for MakeGenericMethod is crashing the runtime
1 participant