Skip to content

IDynamicInterfaceCastable is not supported exception when List.AddRange() is called with AOT compilation #1671

@lhak

Description

@lhak

Describe the bug

The windows community toolkit contains the equivalent to this code (see https://github.com/CommunityToolkit/Windows/blob/c532c1128de4fcb6bb0cb6f5f0918e96fbfdcaf4/components/Helpers/src/NetworkHelper/ConnectionInformation.cs#L53-L58)

var profile = NetworkInformation.GetInternetConnectionProfile();

var names = profile.GetNetworkNames();

List<string> networkNames = new();

if (names?.Count > 0)
{
  networkNames.AddRange(names);
}

The AddRange() method throws an exception with the message "IDynamicInterfaceCastable is not supported for generic type 'System.Collections.Generic.ICollection`1[System.String]" when used with AOT compilation

To Reproduce

  1. Use the code snippet above

Expected behavior

Version Info

CsWinRT compiled from staging/AOT branch

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    AOTbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions