You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Collection expressions pose a significant challenge for trim/AOT support in CsWinRT, because depending on the use case scenario, they can cause Roslyn to generate synthesized types that cannot be seen by developers nor by analyzers. This means that it's impossible for CsWinRT to collect them in the vtable logic and generate CCW vtables for them. Currently, there's no easy way for developers to spot such uses, meaning it's very easy to accidentally introduce code that's not AOT compatible when using collection expressions, which will then crash at runtime.
This issue tracks all the work needed to solve this issue. There's three components to this:
Generator updates to gather CCW info where needed
New analyzers to spot unsupported collection expressions, and warn on them
New diagnostic suppressors to suppress IDE03XX warnings in these scenarios
Changes for collection expressions in code
These changes apply to code that is already using a collection expression (ie. no IDE03XX warning is present):
New analyzer: warn for non empty collection expressions with an lvalue of an interface type without [CollectionBuilder]
Collection expressions pose a significant challenge for trim/AOT support in CsWinRT, because depending on the use case scenario, they can cause Roslyn to generate synthesized types that cannot be seen by developers nor by analyzers. This means that it's impossible for CsWinRT to collect them in the vtable logic and generate CCW vtables for them. Currently, there's no easy way for developers to spot such uses, meaning it's very easy to accidentally introduce code that's not AOT compatible when using collection expressions, which will then crash at runtime.
This issue tracks all the work needed to solve this issue. There's three components to this:
Changes for collection expressions in code
These changes apply to code that is already using a collection expression (ie. no IDE03XX warning is present):
[CollectionBuilder]
T[]
List<T>
This is the expected behavior after these changes:
"Use collection expression for array" (IDE0300)
There are three scenarios here:
[CollectionBuilder]
: no work neededWe need these changes:
"Use collection expression for empty" (IDE0301)
No work needed. All IDE0301 suggestions are valid, as they're only for empty collection expressions.
"Use collection expression for
stackalloc
" (IDE0302)No work needed. No
stackalloc
expression interacts with WinRT marshalling, since they can't be boxed."Use collection expression for
Create()
" (IDE0303)These suggestions are valid only if they cause a collection builder method to be picked up. That is, we only need this:
[CollectionBuilder]
"Use collection expression for builder" (IDE0304)
Same as for IDE0303, that is:
[CollectionBuilder]
"Use collection expression for fluent" (IDE0305)
Same as for IDE0303 and IDE0304, that is:
[CollectionBuilder]
The text was updated successfully, but these errors were encountered: