Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 23, 2026

  • Understand the issue: When [Register("CustomView")] is used without a package prefix, the build fails because XmlImporter doesn't auto-generate a package name
  • Review PR Add proper MSBuild error XA4238 for JCW XML import failures android#10717 and issue Register Attribute breaks build android#10653
  • Analyze the code flow in java-interop
  • Implement fix in XmlImporter.cs to auto-generate a package name when package is empty/missing
  • Add GetPackageName(string ns, string assemblyName) overload to JavaNativeTypeManager for reuse
  • Refactor existing GetPackageName overloads to use the new method
  • Add test for the new behavior
  • Run tests to validate the fix
  • Add SetUp/TearDown to XmlImporterTests to save/restore PackageNamingPolicy

Summary

This PR fixes the issue where using [Register("CustomView")] without a package prefix would cause the build to fail in .NET 10. The fix auto-generates a package name from the partial assembly qualified name when the package attribute is empty or missing in the XML.

Changes

  • Added JavaNativeTypeManager.GetPackageName(string ns, string assemblyName) public method that centralizes package name generation logic
  • Refactored existing GetPackageName(Type) and GetPackageName(TypeDefinition, IMetadataResolver) to use the new method
  • Updated XmlImporter.GeneratePackageFromAssemblyQualifiedName to use the new method instead of duplicating crc64 logic
  • Added SetUp/TearDown methods to XmlImporterTests to properly save and restore PackageNamingPolicy
Original prompt

Review the PR:
@dotnet/android/pull/10717
And issue:
@dotnet/android/issues/10653

I think we need to do something in java-interop when the package is blank in these XML files -- to get back the previous behavior from .NET 9.

Did .NET 9 auto-generate a package name?


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 23, 2026 20:25
When a user uses [Register("CustomView")] without a package prefix, the
XmlImporter now auto-generates a crc64 package name from the partial
assembly qualified name. This restores the previous .NET 9 behavior where
Java types with empty package names could still be built.

Fixes dotnet/android#10653

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 java-interop behavior for blank package in XML files Auto-generate crc64 package name when package is empty in XmlImporter Jan 23, 2026
Copilot AI requested a review from jonathanpeppers January 23, 2026 20:32
…ing crc64 logic

Added new GetPackageName(string ns, string assemblyName) overload to
JavaNativeTypeManager and refactored existing overloads to use it.
XmlImporter now uses this new method instead of duplicating the logic.

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
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

This PR fixes a build failure in .NET 10 when using [Register("CustomView")] without a package prefix. The fix auto-generates a CRC64-based package name from the assembly-qualified type name when the package attribute is empty or missing in XML type definitions.

Changes:

  • Added a new public GetPackageName(string ns, string assemblyName) method to JavaNativeTypeManager to centralize package name generation logic
  • Refactored existing package name generation methods to use the new centralized method, reducing code duplication
  • Enhanced XmlImporter to auto-generate package names when they're missing or empty

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
XmlImporterTests.cs Comprehensive test suite covering package name generation for empty, missing, and explicit package scenarios, including edge cases like nested types and types without namespaces
JavaNativeTypeManager.cs Adds new public method for package name generation and refactors existing overloads to use it, reducing code duplication while maintaining backward compatibility
XmlImporter.cs Implements auto-generation of package names when missing/empty by parsing assembly-qualified names and delegating to JavaNativeTypeManager

Comment on lines +8 to +10
[TestFixture]
public class XmlImporterTests
{
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

The tests in this class depend on JavaNativeTypeManager.PackageNamingPolicy being set to LowercaseCrc64, but they don't explicitly set or restore this value. If other tests modify this static property, these tests could fail. Consider adding SetUp and TearDown methods to save and restore the PackageNamingPolicy, similar to what JavaNativeTypeManagerTests does.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

@copilot can you follow your own suggestion here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added SetUp and TearDown methods to save and restore PackageNamingPolicy, following the pattern from JavaNativeTypeManagerTests. See commit 2feda94.

…ingPolicy

Following the pattern used in JavaNativeTypeManagerTests, save and restore
the PackageNamingPolicy to prevent test interference if other tests modify
this static property.

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
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.

2 participants