teobugslayer / AvaloniaCoreRTDemo

A sample showing how to use Avalonia UI and CoreRT
MIT License
103 stars 19 forks source link

Need help with introducing a third-party library #30

Closed Rwing closed 1 year ago

Rwing commented 1 year ago

Sorry to bother you, but I'm really stuck and don't know what to do. Can you please help me?

I have introduced a third-party library 'NetSparkle' based on your demo. This library has a built-in UI window that displays some information. However when I publish to NativeAot, some items on this window will display abnormally. Everything seems normal in Debug mode, as below.

Steps to reproduce

  1. add nuget package in AvaloniaCoreRTDemo.csproj
    <PackageReference Include="NetSparkleUpdater.UI.Avalonia" Version="3.0.0-preview20230303001" />
  2. add some code in MainWindow.axaml.cs

    public MainWindow(IMainWindow? window)
        {
            this.InitializeComponent(window);
    #if DEBUG
            this.AttachDevTools();
    #endif
    
            var sparkle = new SparkleUpdater("https://netsparkleupdater.github.io/NetSparkle/files/sample-app/appcast.xml", new DSAChecker(SecurityMode.Unsafe))
            {
                UIFactory = new NetSparkleUpdater.UI.Avalonia.UIFactory(null /* Icon; this throws null from 0.10.16 to 0.10.18 and don't have time to debug */)
                {
                    // use the following property to change the main grid background on the update window. nullable.
                },
                // Avalonia version doesn't support separate threads: https://github.com/AvaloniaUI/Avalonia/issues/3434#issuecomment-573446972
                ShowsUIOnMainThread = true,
                //UseNotificationToast = false // Avalonia version doesn't yet support notification toast messages
            };
            // TLS 1.2 required by GitHub (https://developer.github.com/changes/2018-02-01-weak-crypto-removal-notice/)
            sparkle.SecurityProtocolType = System.Net.SecurityProtocolType.Tls12;
            sparkle.StartLoop(true, true);
        }

The UI source code is here

screenshot of correct result image

screenshot of incorrect result image

teobugslayer commented 1 year ago

My "Psychic debugging' tells me that probably NetSparkle is using some reflection and does not handle it well (most probably by swallowing an exception) when it is not present.

I'd suggest to add a rd.xml file, which enables reflection over all NetSparkle types, and see if this helps. If you do not know what "rd.xml" file is, check this article

Unfortunately, not knowing anything about this library, I can't help much more.

Rwing commented 1 year ago

Thank you very much, everything works fine after I added the rd.xml file, that's great! I think I need to learn more about rd.xml file and nativeaot.