Skip to content

Comments

Fix XA3006: Sanitize whitespace-only parameter names in marshal methods LLVM IR generation#10835

Merged
jonathanpeppers merged 5 commits intomainfrom
copilot/fix-compile-assembly-error
Feb 20, 2026
Merged

Fix XA3006: Sanitize whitespace-only parameter names in marshal methods LLVM IR generation#10835
jonathanpeppers merged 5 commits intomainfrom
copilot/fix-compile-assembly-error

Conversation

Copy link
Contributor

Copilot AI commented Feb 18, 2026

Fix for XA3006: Could not compile native assembly file - Invalid parameter name in LLVM IR

Problem

When a managed method has a parameter without a name (or with an empty/whitespace name), the marshal methods generator creates invalid LLVM IR code like:

define void @Java_..._n_1onDraw__Landroid_graphics_Canvas_2(ptr noundef %env, ptr noundef %klass, ptr noundef % )

Note the % ) with no parameter name (or just whitespace), which causes LLVM's llc compiler to fail with: "expected ')' at end of argument list"

Root Cause

In LlvmIrFunction.cs, the constructor checks String.IsNullOrEmpty to determine if a parameter needs a numeric name assignment. However, whitespace-only names like " " pass this check, resulting in invalid LLVM IR output (ptr noundef % ).

Changes Made

  1. LlvmIrFunction.cs: Changed String.IsNullOrEmpty to String.IsNullOrWhiteSpace in the constructor's parameter name validation, so whitespace-only names are properly caught and assigned numeric names.

  2. MarshalMethodsNativeAssemblyGenerator.cs: Added defensive check using String.IsNullOrWhiteSpace when reading parameter names from managed method metadata, normalizing invalid names to null before creating LlvmIrFunctionParameter instances.

  3. LlvmIrGeneratorTests.cs: Added regression tests that:

    • Verify that LlvmIrFunction assigns numeric names to parameters with null, empty, space-only, multi-space, and tab-only names
    • Verify that the LLVM IR generator produces valid output (no % ) or %\t) patterns) when parameters have whitespace-only names

Tasks

Original prompt

This section details on the original issue you should resolve

<issue_title>Could not compile native assembly file: marshal_methods.arm64-v8a.ll</issue_title>
<issue_description>### Android framework version

net10.0-android (Preview)

Affected platform version

VS2026 - December 2025 Feature Update - V18.1.1

Description

When compiling or publishing Android the output shows the following error:

Severity Code Description Project File Line Suppression State
Error (active) XA3006 Could not compile native assembly file: marshal_methods.arm64-v8a.llstderr | C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\36.1.2\tools\binutils\bin\llc.exe: error: C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\36.1.2\tools\binutils\bin\llc.exe: marshal_methods.arm64-v8a.ll:20473:168: error: expected ')' at end of argument liststderr | define void @Java_crc64f2dc31b4200b7cf8_ImageViewerHandler_1quyRbyajYryThP6ghB_n_1onDraw__Landroid_graphics_Canvas_2(ptr noundef %env, ptr noundef %klass, ptr noundef % ) local_unnamed_addr #3stderr |                                                                                                                                                                        ^ RxWhizzMaui (net10.0-android) C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\36.1.2\tools\Xamarin.Android.Common.targets 2180  

As i have no idea where this is coming from i have also no possibility to create a small project which contains the same error. Tried building the project on 3 different development workstations and all gave the same result.

Steps to Reproduce

As i have no idea where this is coming from i have also no possibility to create a small project which contains the same error. Tried building the project on 3 different development workstations and all gave the same result.

Did you find any workaround?

msbuild.binlog.zip

Relevant log output

1>  [llc.EXE stderr] C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\36.1.2\tools\binutils\bin\llc.exe: error: C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\36.1.2\tools\binutils\bin\llc.exe: marshal_methods.arm64-v8a.ll:20480:168: error: expected ')' at end of argument list
1>  [llc.EXE stderr] define void @Java_crc64f2dc31b4200b7cf8_ImageViewerHandler_1quyRbyajYryThP6ghB_n_1onDraw__Landroid_graphics_Canvas_2(ptr noundef %env, ptr noundef %klass, ptr noundef % ) local_unnamed_addr dotnet/android#3
1>  [llc.EXE stderr]                                                                                                                                                                        ^
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\36.1.2\tools\Xamarin.Android.Common.targets(2180,3): error XA3006: Could not compile native assembly file: marshal_methods.arm64-v8a.ll
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\36.1.2\tools\Xamarin.Android.Common.targets(2180,3): error XA3006: 
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\36.1.2\tools\Xamarin.Android.Common.targets(2180,3): error XA3006: stderr | C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\36.1.2\tools\binutils\bin\llc.exe: error: C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\36.1.2\tools\binutils\bin\llc.exe: marshal_methods.arm64-v8a.ll:20480:168: error: expected ')' at end of argument list
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\36.1.2\tools\Xamarin.Android.Common.targets(2180,3): error XA3006: stderr | define void @Java_crc64f2dc31b4200b7cf8_ImageViewerHandler_1quyRbyajYryThP6ghB_n_1onDraw__Landroid_graphics_Canvas_2(ptr noundef %env, ptr noundef %klass, ptr noundef % ) local_unnamed_addr dotnet/android#3
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\36.1.2\tools\Xamarin.Android.Common.targets(2180,3): error XA3006: stderr |                                                                                                                                                                        ^
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\36.1.2\tools\Xamarin.Android.Common.targets(2180,3): error XA3006: 
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\36.1.2\tools\Xamarin.Android.Common.targets(2180,3): error XA3006:
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 11:26 and took 02:28,134 minutes ==========
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@jonathanpeppers</author><body>
Why is the error in the `.binlog` different than above?

(0,1): error JAVA0000: Error in C:\Use...


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 18, 2026 23:00
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix compilation error for native assembly file Fix XA3006: Sanitize whitespace-only parameter names in marshal methods LLVM IR generation Feb 18, 2026
@jonathanpeppers
Copy link
Member

@copilot can you add a test that reproduces the original problem?

…tion and fix LlvmIrFunction constructor

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 19, 2026

@copilot can you add a test that reproduces the original problem?

Added regression tests in cfde3c1. The test file LlvmIrGeneratorTests.cs includes:

  1. FunctionParameterWithInvalidName_GetsNumericName - Parameterized test with null, "", " ", " ", and "\t" that verifies LlvmIrFunction assigns valid numeric names to parameters with invalid names. This test reproduces the original bug - whitespace-only names like " " passed through String.IsNullOrEmpty() in the LlvmIrFunction constructor without getting a numeric name assigned.

  2. GeneratedIR_FunctionWithUnnamedParameter_ProducesValidOutput - End-to-end test that generates actual LLVM IR and verifies the output doesn't contain the invalid % pattern.

I also fixed the root cause in LlvmIrFunction.cs (changing IsNullOrEmptyIsNullOrWhiteSpace on line 445) so the fix is at the right abstraction level.

@jonathanpeppers jonathanpeppers marked this pull request as ready for review February 19, 2026 14:18
Copilot AI review requested due to automatic review settings February 19, 2026 14:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes marshal-methods LLVM IR generation failures (XA3006) when managed method parameters have whitespace-only names, by sanitizing/normalizing such names so LLVM IR always receives valid parameter identifiers.

Changes:

  • Treat whitespace-only parameter names as invalid and auto-assign numeric parameter names in LlvmIrFunction.
  • Normalize whitespace-only metadata parameter names to null in marshal-methods native assembly generation.
  • Add regression tests covering invalid/unnamed parameter names.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsNativeAssemblyGenerator.cs Normalizes whitespace-only managed parameter names to null before creating LLVM IR parameters.
src/Xamarin.Android.Build.Tasks/Utilities/LlvmIrGenerator/LlvmIrFunction.cs Changes name validation to IsNullOrWhiteSpace so whitespace-only names get numeric identifiers.
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/LlvmIrGeneratorTests.cs Adds tests for invalid parameter names and generated IR output.

Comment on lines 14 to 16
/// <summary>
/// Regression test for https://github.com/dotnet/android/issues/10086
///
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regression test comment links to issue #10086, but the PR description/title indicates this change fixes XA3006 whitespace-only parameter names (#10679). Please update the comment to reference the correct issue so future readers can trace the right bug report.

Copilot uses AI. Check for mistakes.
Comment on lines 54 to 60
public void GeneratedIR_FunctionWithUnnamedParameter_ProducesValidOutput ()
{
var parameters = new List<LlvmIrFunctionParameter> {
new LlvmIrFunctionParameter (typeof (IntPtr), "env"),
new LlvmIrFunctionParameter (typeof (IntPtr), "klass"),
new LlvmIrFunctionParameter (typeof (IntPtr), null), // unnamed parameter
};
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is intended to verify generated IR is valid when a parameter name is whitespace-only, but it currently uses a null parameter name. A null name would have been handled even before this fix, so the test won’t fail on the original bug. Consider changing/add test cases to pass whitespace-only names (e.g., " ", "\t") and assert the output does not contain invalid patterns like "% )" / "%\t)" in the function signature.

Copilot uses AI. Check for mistakes.
@jonathanpeppers
Copy link
Member

@copilot apply changes based on the comments in this thread

…ames in end-to-end test

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 20, 2026

@copilot apply changes based on the comments in this thread

Applied both changes in cfb863b:

  1. Fixed issue reference from [release/10.0.1xx-preview4] Update dependencies from dotnet/dotnet #10086 to Could not compile native assembly file: marshal_methods.arm64-v8a.ll #10679
  2. Changed the end-to-end test to use whitespace-only parameter names (" " and "\t") instead of null, and updated assertions to check for the specific invalid patterns % ) and %\t) that would have been produced by the original bug.

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAUI Integration Lane is only failure, and it's broken for unrelated reasons right now.

@jonathanpeppers jonathanpeppers merged commit 600d562 into main Feb 20, 2026
3 of 6 checks passed
@jonathanpeppers jonathanpeppers deleted the copilot/fix-compile-assembly-error branch February 20, 2026 20:50
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.

Could not compile native assembly file: marshal_methods.arm64-v8a.ll

3 participants