Warning CS0618: 'Icon' is obsolete generated in XamlTypeInfo.g.cs when referencing WindowEx in XAML

#278 · closed · 1 comments

View on GitHub ↗

biwasvan

When subclassing or referencing WindowEx in XAML without using any deprecated APIs or the Icon property in user code, the build produces compiler warning CS0618: ``` warning CS0618: 'Icon' is obsolete: 'Please use AppWindow.SetIcon to set icons or the IconId class type' ``` Double-clicking the warning points to the auto-generated XamlTypeInfo.g.cs file (inside the obj/ folder), where the XAML compiler generates metadata reflection entries for all public properties on WindowEx, including the obsolete Icon / TaskBarIcon properties. ### Steps to Reproduce Create a standard WinUI 3 (Windows App SDK) desktop project. Add the NuGet package WinUIEx (version 2.9.3). Set the root element in MainWindow.xaml to WinUIEx.WindowEx: ```XML <w:WindowEx x:Class="MyApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:w="using:WinUIEx" Title="MyApp" Width="1152" Height="864"> <!-- Notice: no Icon attribute is set here --> <Grid /> </w:WindowEx> ``` Subclass WindowEx in MainWindow.xaml.cs: ```C# public sealed partial class MainWindow : WindowEx { public MainWindow() { InitializeComponent(); AppWindow.SetIcon("Assets/AppIcon.ico"); } } ``` *Build the solution.* ### Expected Behavior The project compiles with 0 warnings when the consumer does not explicitly use obsolete members in their own code. ### Actual Behavior The build produces CS0618 originating from XamlTypeInfo.g.cs: ``` [path]\obj\x64\Debug\net8.0-windows10.0.19041.0\XamlTypeInfo.g.cs: warning CS0618: 'Icon' is obsolete: 'Please use AppWindow.SetIcon to set icons or the IconId class type' ```

Comments

dotMorten

Duplicate of https://github.com/dotMorten/WinUIEx/issues/247 See the thread for workaround and link to the “real” issue in WinUI Also I no longer recommend using WindowEx, but use the WindowManager instead which has all the same functionality as extensions to any window type