Fix NativeAOT NullReferenceException in GNOME views#120
Merged
Conversation
…-public fields for reflection Co-authored-by: nlogozzo <17648453+nlogozzo@users.noreply.github.com> Agent-Logs-Url: https://github.com/NickvisionApps/Application/sessions/236a2817-ce25-4a8f-813a-5f89c86b0623
Copilot
AI
changed the title
[WIP] Fix null reference exception in MainWindow constructor
Fix NativeAOT NullReferenceException in GNOME views
Mar 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In NativeAOT mode, the trimmer strips private field reflection metadata by default.
Gtk.Builder.ConnectFields()usesType.GetFields(BindingFlags.NonPublic | ...)to populate[Gtk.Connect]-annotated fields — in NativeAOT this returns an empty array, leaving all connected widgets asnulland causing aNullReferenceExceptionon first access.Changes
MainWindow.cs/PreferencesDialog.cs: Added[DynamicDependency(DynamicallyAccessedMemberTypes.NonPublicFields, typeof(T))]to the private chained constructors (where_builder.Connect(this)is called), instructing the NativeAOT trimmer to preserve non-public field reflection metadata for these types.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/usr/bin/dotnet dotnet restore --no-dependencies /tmp/codeql-scratch-297de09d6e55df2d/dbs/csharp/working/1D28AAEF2CB9C63BCE9DBD21A68FB8D9/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)https://api.github.com/repos/gircore/gir.core/contents/src/Libs/Gtk-4.0/Public/Builder.cs/usr/bin/curl curl -s REDACTED(http block)ocsp.godaddy.com/usr/bin/dotnet dotnet restore --no-dependencies /tmp/codeql-scratch-297de09d6e55df2d/dbs/csharp/working/1D28AAEF2CB9C63BCE9DBD21A68FB8D9/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:
⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.