Skip to content

[AOT] No support in auto-gen code for certain event handler delegates. #1678

@RobsonPontin

Description

@RobsonPontin

Describe the bug
We are testing CsWinRT-preview with AOT support with our product and during runtime when registering to an event handler we get the following exception:

Exception thrown at 0x00007FFD7D37545C (KernelBase.dll) in MyProcess.exe: WinRT originate error - 0x80131515 : 'Cannot provide IReference`1 support for delegate type 'System.Collections.Specialized.NotifyCollectionChangedEventHandler'.'.

So far there are 2 cases which are not supported:

1. "System.Collections.Specialized.NotifyCollectionChangedEventHandler"
2. "System.ComponentModel.PropertyChangedEventHandler"

Internal: https://task.ms/52539411

To Reproduce

  1. Create types like PropertyChanged or CollectionChanged events that derive from those 2 problematics types above.

Expected behavior
After compiling with AOT, the event handler should be able to be registered.

A workaround is to created our own ModuleInitializer extension with the missing mapped types for the Vtable:

private static ComWrappers.ComInterfaceEntry[] LookupVtableEntries(Type type)
{
    var typeName = type.ToString();
    if (typeName == "System.Collections.Specialized.NotifyCollectionChangedEventHandler")
    {
        return new ComWrappers.ComInterfaceEntry[]
        {
                new ComWrappers.ComInterfaceEntry
                {
                    IID = global::ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler.IID,
                    Vtable = global::ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler.AbiToProjectionVftablePtr
                },
        };
    }
    else if (typeName == "System.ComponentModel.PropertyChangedEventHandler")
    {
        return new ComWrappers.ComInterfaceEntry[]
        {
                new ComWrappers.ComInterfaceEntry
                {
                    IID = global::ABI.System.ComponentModel.PropertyChangedEventHandler.IID,
                    Vtable = global::ABI.System.ComponentModel.PropertyChangedEventHandler.AbiToProjectionVftablePtr
                },
        };
    }

    return default;
}

Version Info

  • CsWinRT: 2.1.0-prerelease-ci.240710.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AOTbugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions