Skip to content

[fix-finder] Replace obsolete Log.LogError with thread-safe logging in LinkNativeRuntime task #12237

Description

@github-actions

Problem

LinkNativeRuntime derives from AsyncTask, where the Log property is marked [Obsolete] because calling it from a background thread can hang Visual Studio. Line 87 calls Log.LogError (...) directly with a non-localized inline English string. This failure is already reported with a proper coded error (XA3007 / XA3008) inside NativeLinker.Link, so the direct Log.LogError call is both unsafe and redundant.

Location

  • File(s): src/Xamarin.Android.Build.Tasks/Tasks/LinkNativeRuntime.cs
  • Line(s): 86-88

Current Code

		if (!success) {
			Log.LogError ($"Failed to link native runtime {outputRuntime}");
		}

Suggested Fix

NativeLinker.Link already logs a coded, localized error on every failure path: RunLinker logs XA3007 (Properties.Resources.XA3007) and ExtractDebugSymbols logs XA3008 (Properties.Resources.XA3008). Because a logged error already causes the MSBuild task to fail, the redundant Log.LogError block should simply be removed:

		List<ITaskItem> items = OrganizeCommandLineItemsCLR (abi);
		linker.Link (
			outputRuntime,
			items,
			GetAbiItems (NativeLinkStartFiles, "_NativeLinkStartFiles", abi),
			GetAbiItems (NativeLinkEndFiles, "_NativeLinkEndFiles", abi),
			GetAbiItems (NativeSymbolsToExport, "_NativeSymbolsToExport", abi)
		);

The local bool success variable becomes unused and should be dropped as part of removing the block. Removing the redundant call eliminates the obsolete Log property usage without losing any diagnostic output, since XA3007/XA3008 are already surfaced to the user.

Guidelines

  • Do NOT use the [Obsolete] Log property on AsyncTask-derived tasks; use the thread-safe helpers (LogCodedError, LogMessage, LogDebugMessage, etc.).
  • User-facing error messages must come from Properties.Resources with a stable XA#### code, never a raw inline English string.
  • Follow dotnet/android formatting (tabs, space before ().

Acceptance Criteria

  • The direct Log.LogError call in LinkRuntime is removed.
  • Link failures are still reported (via the existing XA3007/XA3008 coded errors in NativeLinker).
  • No unused local variable warnings are introduced.
  • All tests pass
  • No new warnings introduced

Fix-finder metadata

  • Script: 07-asynctask-log-property
  • Score: 28/30 (actionability: 10, safety: 8, scope: 10)

Generated by Nightly Fix Finder · 85.5 AIC · ⌖ 17.4 AIC · ⊞ 9.4K ·

  • expires on Aug 2, 2026, 2:26 AM UTC

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions