-
Notifications
You must be signed in to change notification settings - Fork 802
Closed
Labels
bugSomething isn't workingSomething isn't workingneeds-author-feedbackAsked author to supply more information.Asked author to supply more information.no-recent-activity
Description
Describe the bug
After publishing a self contained, trimmed single file WinUI 3 executable, most things work normally. However, if you try to set the Content property on a ContentControl it will throw an exception:
[InvalidCastException] No such interface supported
int RoutedEventHandler.Do_Abi_Invoke(thisPtr, sender, e) >
RoutedEventHandler EventState.GetEventInvoke(sender, e) >
void PageViewer.OnApplyTemplate(sender, args) in PageViewer.cs:69 >
void PageViewer.SetCurrentPage(index) in PageViewer.cs:278 >
void ContentControl.set_Content(value) >
void IContentControlMethods.set_Content(_obj, value) >
void ExceptionHelpers.ThrowExceptionForHR(hr)
I assume the failure is due to IContentControlMethods getting trimmed.
Steps to reproduce the bug
Create a self-contained unpackaged WinUI app, and publish as trimmed and single file.
NuGet package version
Microsoft.WindowsAppSDK 1.6.250205002
1.7.250208002-preview1 has a similar error too:
[InvalidCastException] Specified cast is not valid.
int RoutedEventHandler.Do_Abi_Invoke(thisPtr, sender, e) >
RoutedEventHandler EventState.GetEventInvoke(sender, e) >
void PageViewer.OnApplyTemplate(sender, args) in PageViewer.cs:69 >
void PageViewer.SetCurrentPage(index) in PageViewer.cs:278 >
void ContentControl.set_Content(value) >
void IContentControlMethods.set_Content(_obj, value) >
void ExceptionHelpers.ThrowExceptionForHR(hr)
Windows version
Windows 11 24H2
Workaround
As a workaround, adding the following to the project csproj file solves the problem at the cost of adding ~7MB to the executable:
<ItemGroup>
<TrimmerRootAssembly Include="Microsoft.WinUI"/>
</ItemGroup>Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingneeds-author-feedbackAsked author to supply more information.Asked author to supply more information.no-recent-activity