You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
src/Xamarin.Android.Build.Debugging.Tasks/Tasks/WaitForAppDetection.cs is shipped product code that has not been opted into nullable reference types. It is a small, self-contained AsyncTask whose only field can legitimately be null — it is populated from GetRegisteredTaskObjectAssemblyLocal<T>, which returns null when no task object is registered. The code already guards against null, so opting in to NRT simply makes the existing contract explicit. Its sibling in the same folder, DetectIfAppWasUninstalled.cs, was already converted in #11598, which explicitly left this file for later.
Line(s): line 1 (add directive) and line 16 (field declaration)
Current Code
usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Threading;usingMicrosoft.Build.Framework;usingMicrosoft.Build.Utilities;usingMono.AndroidTools;usingMicrosoft.Android.Build.Tasks;namespaceXamarin.Android.Tasks{publicclassWaitForAppDetection:AsyncTask{publicoverridestringTaskPrefix=>"WFAD";System.Threading.Tasks.Task<List<AndroidInstalledPackage>>getPackagesAsync;publicoverrideboolExecute(){varkey=ProjectSpecificTaskObjectKey(DetectIfAppWasUninstalled.GetPackagesAsyncKey);getPackagesAsync=BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<System.Threading.Tasks.Task<List<AndroidInstalledPackage>>>(key,RegisteredTaskObjectLifetime.Build);returnbase.Execute();}publicasyncoverrideSystem.Threading.Tasks.TaskRunTaskAsync(){LogDebugMessage("Waiting for DetectIfAppWasUninstalled...");if(getPackagesAsync==null)return;awaitgetPackagesAsync;LogDebugMessage("DetectIfAppWasUninstalled Completed.");return;}}}
Suggested Fix
The owning project (Xamarin.Android.Build.Debugging.Tasks.csproj) targets netstandard2.0 (LangVersion 12), so do NOT use ArgumentNullException.ThrowIfNull (it requires net6.0+). No null-throwing is needed here at all — only annotations.
Add #nullable enable as the very first line of the file (no preceding blank lines):
#nullable enable
usingSystem;
Make the getPackagesAsync field nullable. It is left unassigned until Execute () runs, and GetRegisteredTaskObjectAssemblyLocal<T> returns null when nothing is registered:
No other changes are required: the existing if (getPackagesAsync == null) return; guard in RunTaskAsync () already handles the null case, so there are no remaining nullable warnings.
Guidelines
Follow Mono formatting style: tabs, space before ( and [.
Never use the ! (null-forgiving) operator — check for null explicitly (already done here).
This is a netstandard2.0 project — do NOT use ArgumentNullException.ThrowIfNull.
Problem
src/Xamarin.Android.Build.Debugging.Tasks/Tasks/WaitForAppDetection.csis shipped product code that has not been opted into nullable reference types. It is a small, self-containedAsyncTaskwhose only field can legitimately benull— it is populated fromGetRegisteredTaskObjectAssemblyLocal<T>, which returnsnullwhen no task object is registered. The code already guards againstnull, so opting in to NRT simply makes the existing contract explicit. Its sibling in the same folder,DetectIfAppWasUninstalled.cs, was already converted in #11598, which explicitly left this file for later.Location
src/Xamarin.Android.Build.Debugging.Tasks/Tasks/WaitForAppDetection.csCurrent Code
Suggested Fix
The owning project (
Xamarin.Android.Build.Debugging.Tasks.csproj) targetsnetstandard2.0(LangVersion 12), so do NOT useArgumentNullException.ThrowIfNull(it requiresnet6.0+). No null-throwing is needed here at all — only annotations.#nullable enableas the very first line of the file (no preceding blank lines):getPackagesAsyncfield nullable. It is left unassigned untilExecute ()runs, andGetRegisteredTaskObjectAssemblyLocal<T>returnsnullwhen nothing is registered:No other changes are required: the existing
if (getPackagesAsync == null) return;guard inRunTaskAsync ()already handles thenullcase, so there are no remaining nullable warnings.Guidelines
(and[.!(null-forgiving) operator — check fornullexplicitly (already done here).netstandard2.0project — do NOT useArgumentNullException.ThrowIfNull.DetectIfAppWasUninstalled.csin the same directory (see [fix-finder] Enable nullable reference types inDetectIfAppWasUninstalled.cs#11598).Acceptance Criteria
#nullable enableis the first line of the file (no preceding blank lines).getPackagesAsyncis declared asSystem.Threading.Tasks.Task<List<AndroidInstalledPackage>>?(nullable).!(null-forgiving) operator.Fix-finder metadata
01-nullable-reference-types28/30(actionability:9, safety:9, scope:10)