Skip to content

[fix-finder] Move hardcoded IL6001 warning in CheckForObsoletePreserveAttributeStep to Resources.resx #11593

@github-actions

Description

@github-actions

Problem

CheckForObsoletePreserveAttributeStep.cs line 27 passes a hardcoded string literal to LogCodedWarning instead of using a resource string from Properties.Resources. This means the customer-facing warning message is not localizable, which is inconsistent with the rest of the codebase where all coded warnings use resource strings.

Location

  • File(s): src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/CheckForObsoletePreserveAttributeStep.cs
  • Line(s): 27

Current Code

log.LogCodedWarning ("IL6001", $"Assembly '{assembly.Name.Name}' contains reference to obsolete attribute 'Android.Runtime.PreserveAttribute'. Members with this attribute may be trimmed. Please use System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute instead");

Suggested Fix

1. Add a using alias at the top of CheckForObsoletePreserveAttributeStep.cs (matching the pattern used by other files in the same Linker/MonoDroid.Tuner/ directory, e.g. FixAbstractMethodsStep.cs and FixLegacyResourceDesignerStep.cs):

using Resources = Xamarin.Android.Tasks.Properties.Resources;

2. Replace line 27 with:

log.LogCodedWarning ("IL6001", Resources.IL6001, assembly.Name.Name);

3. Add resource entry to the English src/Xamarin.Android.Build.Tasks/Properties/Resources.resx (alphabetically among existing entries):

<data name="IL6001" xml:space="preserve">
  <value>Assembly '{0}' contains reference to obsolete attribute 'Android.Runtime.PreserveAttribute'. Members with this attribute may be trimmed. Please use System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute instead</value>
</data>

4. Add the corresponding property to src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs:

/// <summary>
///   Looks up a localized string similar to Assembly '{0}' contains reference to obsolete attribute 'Android.Runtime.PreserveAttribute'. Members with this attribute may be trimmed. Please use System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute instead.
/// </summary>
public static string IL6001 {
    get {
        return ResourceManager.GetString("IL6001", resourceCulture);
    }
}

Guidelines

  • Only modify the English Resources.resx — never modify non-English *.resx or *.lcl files
  • Follow Mono formatting style (tabs, space before ()
  • The owning project (Xamarin.Android.Build.Tasks.csproj) targets netstandard2.0 — the suggested fix only uses Properties.Resources and LogCodedWarning, both available on netstandard2.0
  • Keep the warning code as IL6001 (do not change it to an XA code — this is a trimmer-pipeline step and the code is verified by an existing test)
  • The using alias pattern (using Resources = Xamarin.Android.Tasks.Properties.Resources;) is the established convention in the Linker/MonoDroid.Tuner/ directory

Acceptance Criteria

  • The hardcoded string on line 27 is replaced with a resource reference (Resources.IL6001)
  • A using Resources = Xamarin.Android.Tasks.Properties.Resources; alias is added to the file
  • The resource string IL6001 is added to the English Resources.resx
  • Resources.Designer.cs is updated with the IL6001 property
  • The existing test in LinkerTests.cs (which checks for "warning IL6001" and "obsolete attribute 'Android.Runtime.PreserveAttribute'") still passes — the message text must not change
  • All tests pass
  • No new warnings introduced

Fix-finder metadata

  • Script: 08-string-literal-error-messages
  • Score: 26/30 (actionability: 10, safety: 8, scope: 8)

Generated by Nightly Fix Finder · ● 24.9M ·

  • expires on Jun 13, 2026, 2:32 AM UTC

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions