-
Notifications
You must be signed in to change notification settings - Fork 63
[Java.Interop.Tools.JavaCallableWrappers] Improve missing attribute #1369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jonathanpeppers
merged 1 commit into
dotnet:main
from
jonpryor:dev/jonpryor/jonp-improve-GetRequiredAttribute-exception
Oct 20, 2025
Merged
[Java.Interop.Tools.JavaCallableWrappers] Improve missing attribute #1369
jonathanpeppers
merged 1 commit into
dotnet:main
from
jonpryor:dev/jonpryor/jonp-improve-GetRequiredAttribute-exception
Oct 20, 2025
+11
−3
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Context: bc44f08 If "something goes wrong" and the `*.jlo.xml` files contain `//jcw-types/type` elements that are *missing* the `//type/@package` attribute, then an exception is thrown: System.InvalidOperationException: Missing required attribute 'package' at Java.Interop.Tools.JavaCallableWrappers.Extensions.XmlExtensions.GetRequiredAttribute(XElement xml, String name) at Java.Interop.Tools.JavaCallableWrappers.Adapters.XmlImporter.ImportType(XElement xml) at Java.Interop.Tools.JavaCallableWrappers.Adapters.XmlImporter.Import(XElement xml) at Xamarin.Android.Tasks.JavaObjectsXmlFile.Import(String filename, JavaObjectsXmlFileReadType readType) at Xamarin.Android.Tasks.GenerateJavaCallableWrappers.GenerateWrappers(List`1 assemblies) at Xamarin.Android.Tasks.GenerateJavaCallableWrappers.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() Which is all well and good, except ***I have no idea what's broken***. *Something* within dotnet/android should be updated so that the file causing the exception is mentioned, but we can also improve the `InvalidOperationException` to contain at least a "breadcrumb" for what's going wrong. Update the `InvalidOperationException` to also include the contents of the `XElement.ToString()` which is missing the required attribute. We can then at least search file contents to find the "offending" file. This provides a more useful exception message: System.InvalidOperationException: Missing required attribute 'package' within element `<type name="SKCanvasElementImpl" package="" application_java_class="android.support.multidex.MultiDexApplication" mono_runtime_initialization="mono.MonoPackageManager.LoadApplication (context);" extends_type="Uno.WinUI.Graphics2DSK.SKCanvasElement" partial_assembly_qualified_name="SKCanvasElementImpl, SamplesApp"> <constructors> <constructor name="SKCanvasElementImpl" method="n_.ctor:(Landroid/content/Context;)V:" jni_signature="(Landroid/content/Context;)V" managed_parameters="Android.Content.Context, Mono.Android" params="android.content.Context p0" retval="void" is_dynamically_registered="True" super_call="p0" activate_call="p0" /> </constructors> </type>`. at Java.Interop.Tools.JavaCallableWrappers.Extensions.XmlExtensions.GetRequiredAttribute(XElement xml, String name) at Java.Interop.Tools.JavaCallableWrappers.Adapters.XmlImporter.ImportType(XElement xml) at Java.Interop.Tools.JavaCallableWrappers.Adapters.XmlImporter.Import(XElement xml) at Xamarin.Android.Tasks.JavaObjectsXmlFile.Import(String filename, JavaObjectsXmlFileReadType readType) at Xamarin.Android.Tasks.GenerateJavaCallableWrappers.GenerateWrappers(List`1 assemblies) at Xamarin.Android.Tasks.GenerateJavaCallableWrappers.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() Which shows *two* problems: 1. The `package` attribute *is* present, but 2. The `package` attribute is the empty string. Which should be supported! The global package is A Thing That Exists™; it should be supported! (Has *been* supported?!) Update `XmlImporter.ImportType()` so that `package` is *not* required. Update `tests/Java.Interop.Tools.JavaCallableWrappers-Tests` to add an explicit test for a type in the Java global package.
jonathanpeppers
approved these changes
Oct 20, 2025
jonathanpeppers
pushed a commit
that referenced
this pull request
Oct 20, 2025
…1369) Context: bc44f08 If "something goes wrong" and the `*.jlo.xml` files contain `//jcw-types/type` elements that are *missing* the `//type/@package` attribute, then an exception is thrown: System.InvalidOperationException: Missing required attribute 'package' at Java.Interop.Tools.JavaCallableWrappers.Extensions.XmlExtensions.GetRequiredAttribute(XElement xml, String name) at Java.Interop.Tools.JavaCallableWrappers.Adapters.XmlImporter.ImportType(XElement xml) at Java.Interop.Tools.JavaCallableWrappers.Adapters.XmlImporter.Import(XElement xml) at Xamarin.Android.Tasks.JavaObjectsXmlFile.Import(String filename, JavaObjectsXmlFileReadType readType) at Xamarin.Android.Tasks.GenerateJavaCallableWrappers.GenerateWrappers(List`1 assemblies) at Xamarin.Android.Tasks.GenerateJavaCallableWrappers.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() Which is all well and good, except ***I have no idea what's broken***. *Something* within dotnet/android should be updated so that the file causing the exception is mentioned, but we can also improve the `InvalidOperationException` to contain at least a "breadcrumb" for what's going wrong. Update the `InvalidOperationException` to also include the contents of the `XElement.ToString()` which is missing the required attribute. We can then at least search file contents to find the "offending" file. This provides a more useful exception message: System.InvalidOperationException: Missing required attribute 'package' within element `<type name="SKCanvasElementImpl" package="" application_java_class="android.support.multidex.MultiDexApplication" mono_runtime_initialization="mono.MonoPackageManager.LoadApplication (context);" extends_type="Uno.WinUI.Graphics2DSK.SKCanvasElement" partial_assembly_qualified_name="SKCanvasElementImpl, SamplesApp"> <constructors> <constructor name="SKCanvasElementImpl" method="n_.ctor:(Landroid/content/Context;)V:" jni_signature="(Landroid/content/Context;)V" managed_parameters="Android.Content.Context, Mono.Android" params="android.content.Context p0" retval="void" is_dynamically_registered="True" super_call="p0" activate_call="p0" /> </constructors> </type>`. at Java.Interop.Tools.JavaCallableWrappers.Extensions.XmlExtensions.GetRequiredAttribute(XElement xml, String name) at Java.Interop.Tools.JavaCallableWrappers.Adapters.XmlImporter.ImportType(XElement xml) at Java.Interop.Tools.JavaCallableWrappers.Adapters.XmlImporter.Import(XElement xml) at Xamarin.Android.Tasks.JavaObjectsXmlFile.Import(String filename, JavaObjectsXmlFileReadType readType) at Xamarin.Android.Tasks.GenerateJavaCallableWrappers.GenerateWrappers(List`1 assemblies) at Xamarin.Android.Tasks.GenerateJavaCallableWrappers.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() Which shows *two* problems: 1. The `package` attribute *is* present, but 2. The `package` attribute is the empty string. Which should be supported! The global package is A Thing That Exists™; it should be supported! (Has *been* supported?!) Update `XmlImporter.ImportType()` so that `package` is *not* required. Update `tests/Java.Interop.Tools.JavaCallableWrappers-Tests` to add an explicit test for a type in the Java global package.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: bc44f08
If "something goes wrong" and the
*.jlo.xmlfiles contain//jcw-types/typeelements that are missing the//type/@packageattribute, then an exception is thrown:Which is all well and good, except I have no idea what's broken.
Something within dotnet/android should be updated so that the file causing the exception is mentioned, but we can also improve the
InvalidOperationExceptionto contain at least a "breadcrumb" for what's going wrong.Update the
InvalidOperationExceptionto also include the contents of theXElement.ToString()which is missing the required attribute. We can then at least search file contents to find the "offending" file.This provides a more useful exception message:
Which shows two problems:
packageattribute is present, butpackageattribute is the empty string.Which should be supported! The global package is A Thing That Exists™; it should be supported! (Has been supported?!)
Update
XmlImporter.ImportType()so thatpackageis not required.Update
tests/Java.Interop.Tools.JavaCallableWrappers-Teststo add an explicit test for a type in the Java global package.