Bug 47867

Summary: assert at sre.c:1553 in System.Reflection.Emit.TypeBuilder.create_runtime_class
Product: [Mono] Runtime Reporter: Robert van der Boon <rjvdboon>
Component: ReflectionAssignee: Aleksey Kliger <aleksey>
Severity: normal CC: masafa, mono-bugs+mono, mono-bugs+runtime
Priority: ---    
Version: master   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Test file
Assert Abort Stacktrace
Standalone reproduction

Description Robert van der Boon 2016-11-24 17:31:37 UTC
Created attachment 18657 [details]
Test file

When using Rhino mocks to create a DynamicMock for an interface with a generic method an assertion is raised and the process dies.

See attached both a test case and the stacktrace.
compile the testcase with:
  mcs -t:exe -r:Rhino.Mocks test.cs
run with:
  mono --debug test.exe

If you compile with -DLESS_GENERIC the test succeeds (prints: "Done: 00000000-0000-0000-0000-000000000000")
Comment 1 Robert van der Boon 2016-11-24 17:32:04 UTC
Created attachment 18658 [details]
Assert Abort Stacktrace
Comment 2 Aleksey Kliger 2016-11-28 17:36:36 UTC
This is one of our awesome corner cases where a finished typebuilder references a generic instantiation of an unfinished one.  reflection_setup_internal_class minimally initializes the referenced type, but it doesn't have enough info to make the call on whether the type will be a generic or not. But when we go to instantiate in mono_reflection_bind_generic_parameters we expect to see a generic type definition.

Working on a minimal standalone reproduction...
Comment 3 Aleksey Kliger 2016-11-28 18:04:48 UTC
Created attachment 18698 [details]
Standalone reproduction

Standalone reproduction without dependencies.
Comment 4 Aleksey Kliger 2016-12-01 15:38:18 UTC
Fixed in Mono master https://github.com/mono/mono/commit/a713a14521da8ddf992c4a3e64855d56cb7897a3