Skip to content

Fix IL3050 NativeAOT warnings in WinUI and GNOME Program.cs#115

Merged
nlogozzo merged 2 commits intofeat/aotfrom
copilot/fix-aot-compile-warnings
Mar 20, 2026
Merged

Fix IL3050 NativeAOT warnings in WinUI and GNOME Program.cs#115
nlogozzo merged 2 commits intofeat/aotfrom
copilot/fix-aot-compile-warnings

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 20, 2026

Nickvision.Desktop recently annotated ConfigureWinUI<T>() and ConfigureAdw<T>() with [RequiresDynamicCode]. Calling these from unannotated Main methods produces IL3050 warnings under NativeAOT.

Changes

  • Nickvision.Application.WinUI/Program.cs — Added [RequiresDynamicCode] to Main to propagate the attribute from ConfigureWinUI<T>()
  • Nickvision.Application.GNOME/Program.cs — Added [RequiresDynamicCode] to Main to propagate the attribute from ConfigureAdw<T>()
[STAThread]
[RequiresDynamicCode("Calls ConfigureWinUI<T>() which may use dynamic code generation.")]
private static void Main(string[] args) { ... }
[RequiresDynamicCode("Calls ConfigureAdw<T>() which may use dynamic code generation.")]
public static async Task Main(string[] args) { ... }

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • crl.godaddy.com
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /tmp/codeql-scratch-297de09d6e55df2d/dbs/csharp/working/7F0AD5B89EC078FE77CFD6BDA2F52E08/missingpackages_workingdir --packages /tmp/codeql-scratch-297de09d6e55df2d/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /tmp/codeql-scratch-297de09d6e55df2d/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
  • ocsp.godaddy.com
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /tmp/codeql-scratch-297de09d6e55df2d/dbs/csharp/working/7F0AD5B89EC078FE77CFD6BDA2F52E08/missingpackages_workingdir --packages /tmp/codeql-scratch-297de09d6e55df2d/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /tmp/codeql-scratch-297de09d6e55df2d/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

… to Main methods

Co-authored-by: nlogozzo <17648453+nlogozzo@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix AOT compile warnings for dynamic code usage Fix IL3050 NativeAOT warnings in WinUI and GNOME Program.cs Mar 20, 2026
Copilot AI requested a review from nlogozzo March 20, 2026 13:57
@nlogozzo
Copy link
Copy Markdown
Member

@copilot Does this prevent NativeAOT benefits?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 20, 2026

@copilot Does this prevent NativeAOT benefits?

No, this does not prevent NativeAOT benefits. Here's why:

[RequiresDynamicCode] is an annotation propagator, not a suppressor. It tells the AOT toolchain "this call chain involves methods that may use dynamic code." Since Main is the entry point, there is no further caller to propagate to — the annotation chain terminates here correctly.

The NativeAOT compilation itself is unaffected:

  • The binary is still compiled fully to native code (no JIT)
  • Startup and runtime performance benefits are preserved
  • The [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] attribute on T in the Desktop library's ConfigureWinUI<T>() / ConfigureAdw<T>() ensures the AOT linker preserves the necessary constructors for those types at link time

The only alternative to silence these warnings without propagation would be to suppress them with [UnconditionalSuppressMessage], which would be less honest about the call chain. Propagating [RequiresDynamicCode] to Main is the correct pattern when the entry point is the end of the call chain.

@nlogozzo nlogozzo marked this pull request as ready for review March 20, 2026 16:33
@nlogozzo nlogozzo merged commit b79632c into feat/aot Mar 20, 2026
1 check passed
@nlogozzo nlogozzo deleted the copilot/fix-aot-compile-warnings branch March 20, 2026 16:33
nlogozzo added a commit that referenced this pull request Mar 21, 2026
* feat: Update deps

* Fix IL3050 NativeAOT warnings in WinUI and GNOME Program.cs (#115)

* Initial plan

* Fix IL3050 NativeAOT warnings by adding RequiresDynamicCode attribute to Main methods

Co-authored-by: nlogozzo <17648453+nlogozzo@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: nlogozzo <17648453+nlogozzo@users.noreply.github.com>

* fix: Sources

* fix: NativeAOT - replace reflection-based XAML bindings in SettingsPage (#117)

* Initial plan

* fix: replace DisplayMemberPath with compiled x:Bind ItemTemplate for NativeAOT compatibility

Co-authored-by: nlogozzo <17648453+nlogozzo@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: nlogozzo <17648453+nlogozzo@users.noreply.github.com>

* feat: Update license

* fix: Missing sources

* feat: Bindable item

* feat: Update deps

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: nlogozzo <17648453+nlogozzo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants