Skip to content

Any chance of a short term fix for casts not being picked up with AOT? #2516

Description

@benstevens48

Description

I have just migrated a UWP app to WindowsAppSDK + CSWinRT + NativeAOT. However, it is a large app, and I keep on finding bugs which are present in the published version but not when debugging, primarily I think due to types not being picked up by the source generator (not sure exactly how it works). Often this is when the type is used via a cast - mostly I am using the C# as operator.

Steps To Reproduce

To give an example, I just realised that my custom media controls were not fading in/out in the published version of my app. Then I ran it in debug to see what this issue was and it worked fine! After being very confused for some time, based on some previous experiences I replaced this line

visibleStateGroup = GetTemplateChild("ControlPanelVisibilityStates") as VisualStateGroup;

with this line

visibleStateGroup = GetTemplateChild("ControlPanelVisibilityStates").As<VisualStateGroup>();

and it started working again. But it was very difficult to debug, especially as I had to publish the app every time to test a possible fix. Plus I have hundreds of places like this where I am using the C# as operator and it makes my code seem very fragile. This is an example of not such a bag bug but I have also had crashing bugs as well.

I realise this will probably be fixed by v3 and you are doing a lot of good work on it but it seems like it may still be some time before that is released(?).

Expected Behavior

Types picked up by source generator as needed.

Version Info

2.3 prerelease

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions