Skip to content

Application crashes with "Parent class failed to load, due to: Invalid generic instantiation assembly" #71424

Closed

Description

@AntonKosenkoPro

Description

Hello, we are developing DevExpress .NET MAUI controls and experienced crashes when trying to run our DevExpress.Data library on real iPhone. It seems that the issue related to iOS linker. This issue doesn't appear on Xamarin.Forms and doesn't appear on android or iOS simulator.

It's severe for us because we can't run full-functionality DataGrid without DevExpress.Data library.

Thanks

Steps to Reproduce

Please contact David Ortinau and Jonathan Dick to download the ZIP archive with the sample reproducing the issue- we emailed them this repro info, because we cannot make it public here. Alternatively, please email [email protected] and we will share the attachment with you directly.

Version with bug

6.0.400 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

All iOS versions on real iPhone

Did you find any workaround?

No

Relevant log output

No response

Activity

  1. PureWeen commented on Jun 22, 2022

    @PureWeen
    Member
  2. rolfbjarne commented on Jun 27, 2022

    @rolfbjarne
    Member

    I can reproduce this with the provided test case, I'll look into what's happening

  3. ghost added
    untriaged
    on Jun 29, 2022
  4. transferred this issue fromdotnet/mauion Jun 29, 2022
  5. rolfbjarne commented on Jun 29, 2022

    @rolfbjarne
    Member

    This is weird, but I believe it's a runtime bug, and whatever the linker does just exposes that runtime bug, because:

    1. The assembly with the broken types isn't modified by the linker.
    2. Adding random code makes other random things either work or break.

    This is the class hierarchy that fails to load:

    public abstract class GenericInvoker<Signature, ImplType>
    	where ImplType: GenericInvoker<Signature, ImplType>
    {
    }
    
    public abstract class TransformBuilder: GenericInvoker<Func<Delegate, Delegate, bool, Delegate>, TransformBuilder.Impl<object, object>> {
        public class Impl<ColumnType, TransformedType>: TransformBuilder { }
    }

    A couple this I've tried that can randomly change the results:

    • Add a new class TransformBuilder2 with exactly the same base class. Now both TransformBuilder and TransformBuilder2 work...
    • Replace method implementations in TransformBuilder with dummy implementations that just throw an exception.

    I debugged in lldb, and this is what I've found:

    The error message:

    Parent class failed to load, due to: Invalid generic instantiation

    comes from here:

    mono_class_set_type_load_failure (klass, "Invalid generic instantiation");

    Debugging in lldb reveals that the check fails here:

    /*FIXME maybe we need the same this as verifier_class_is_assignable_from*/
    if (!mono_class_is_assignable_from_slow (ctr, paramClass))
    return FALSE;

    And that happens because the mono_class_has_parent check fails here, when I believe it should succeed:

    if (mono_class_has_parent (candidate, target))
    return TRUE;

    At the entry to mono_class_has_parent, this is what inspection of the two arguments and their class hierarchy shows:

    (lldb) p target
    (MonoClass *) $70 = 0x0000000111a7fe58
    (lldb) p target->name
    (const char *) $71 = 0x0000000118ab1e55 "GenericInvoker`2"
    (lldb) p target->idepth
    (guint16) $72 = 2
    (lldb) p target->supertypes[0]->name
    (const char *) $73 = 0x0000000110fb576d "Object"
    (lldb) p target->supertypes[1]->name
    (const char *) $74 = 0x0000000118ab1e55 "GenericInvoker`2"
    (lldb) p target->supertypes[1]
    (MonoClass *) $75 = 0x0000000111a7fe58
    

    and this is the candidate MonoClass:

    (lldb) p candidate->name
    (const char *) $76 = 0x0000000118ab1dd9 "Impl`2"
    (lldb) p candidate->idepth
    (guint16) $77 = 4
    (lldb) p candidate->supertypes[0]->name
    (const char *) $78 = 0x0000000110fb576d "Object"
    (lldb) p candidate->supertypes[1]->name
    (const char *) $79 = 0x0000000118ab1e55 "GenericInvoker`2"
    (lldb) p candidate->supertypes[2]->name
    (const char *) $80 = 0x0000000118b0d5ce "TransformBuilder"
    (lldb) p candidate->supertypes[3]->name
    (const char *) $81 = 0x0000000118ab1dd9 "Impl`2"
    (lldb) p candidate->supertypes[1]
    (MonoClass *) $82 = 0x000000011247da88
    (lldb) p candidate->supertypes[2]
    (MonoClass *) $83 = 0x0000000112409208
    (lldb) p candidate->supertypes[3]
    (MonoClass *) $84 = 0x0000000111a7c4d8
    

    In particular notice how candidate->supertypes[1] != target->supertypes[1]

    Here's a dump of both in case that's helpful: https://gist.github.com/rolfbjarne/4b5cb4c4d6baa59ac2ef310c1b32491f

    I'm not really sure what's going on here, but this looks like a runtime bug to me, so I've moved it here.

  6. rolfbjarne commented on Jun 29, 2022

    @rolfbjarne
    Member
  7. 12 remaining items

  8. rolfbjarne commented on Jun 30, 2022

    @rolfbjarne
    Member

    I've sent repro case privately.

  9. vargaz commented on Jul 4, 2022

    @vargaz
    Contributor

    What is the stacktrace when the failure happens ?

  10. removed
    untriaged
    on Jul 5, 2022
  11. added this to the 6.0.x milestone on Jul 5, 2022
  12. ghost added
    in-pr
    on Jul 6, 2022
  13. ghost removed
    in-pr
    on Jul 7, 2022
  14. ghost locked as resolved and limited conversation to collaborators on Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions