Skip to content

InvaildCastException occurs when the argument is passed in as a collection expression #1729

Closed

Description

Describe the bug

InvaildCastException occurs when the argument is passed in as a collection expression
传入参数为集合表达式时会发生 InvaildCastException

To Reproduce

Compositor. CreateEffectFactory() have multiple overloaded method, one of the second parameter for IEnumerable, at this time if in the second parameter to set expression directly, causing InvaildCastException
Compositor.CreateEffectFactory() 方法有多个重载,其中一个第二个参数为 IEnumerable,这时如果在第二个参数中直接传入集合表达式,引发 InvaildCastException
{CC80183B-4C3B-431D-93F0-ECBFCE4FEAFB}
caf934614c1344212b350007c479ec7f
f13e29d919a261020e21de40b27c3622
9cb94d616e2a7dba14cb33d7ce92c3e4

Expected behavior

Provide warning or support collection expression in parameter

Version Info

CsWinRT 2.1.1
Windows SDK 10.0.26100.0
.NET SDK 9.0.0-preview7

Additional context

Found in the process of debugging, set the type of the expression is <>z_ReadOnlySingleElementList
调试的过程中,发现集合表达式生成的类型是<>z_ReadOnlySingleElementList
646565e7042e4e16ff4a2f15458a9c6e

Activity

  1. hez2010 commented on Sep 3, 2024

    @hez2010
    Contributor

    Manodasan Wignarajah (@manodasanW) I think we should not use source generator at the first place, instead we should generate an assembly just like what WPF does, so that things like this can get covered.

  2. manodasanW commented on Sep 4, 2024

    @manodasanW
    Member

    Sergio did bring up a related idea with separate assembly for the generic instantiations and vtable lookup table that is being considered. But I don't think that would solve this problem where these are internal .NET types that CsWinRT won't directly be aware of unless you were thinking of something there?

    The plan to address that is to make use of the statically known interface on the projection and provide a vtable for that when the one for the class isn't available. This is tracked by #1661. The tricky part will be minimizing size impact.

  3. Sergio0694 commented on Nov 26, 2024

    @Sergio0694
    Member

    Manodasan Wignarajah (@manodasanW) pretty sure this should be fixed with 2.2, right? It's just passing a List<string> explicitly 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    AOTbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions