dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 533 forks source link

`ApplicationAttribute` XML invalid character error, does not give line number or file path #8349

Open blmiles opened 1 year ago

blmiles commented 1 year ago

Android application type

.NET Android (net7.0-android, etc.)

Affected platform version

VS 2022, Version 17.7.3, .Net 7, Maui, Android App

Description

This was building on the weekend, I'm made no changes to the project. The android App was running on a target device (NOT an emulator) running Android 13.

When I now build I get the following error: Error XAGJS7004 System.ArgumentException: ' ', hexadecimal value 0x0C, is an invalid character.

I have check every possible file and line I know to check. No idea why this happens NOW. Zero changes over the weekend.

Here's the full error: _Severity Code Description Project File Line Suppression State Error XAGJS7004 System.ArgumentException: ' ', hexadecimal value 0x0C, is an invalid character. at System.Xml.XmlEncodedRawTextWriter.WriteAttributeTextBlock(Char pSrc, Char pSrcEnd) at System.Xml.XmlEncodedRawTextWriter.WriteString(String text) at System.Xml.XmlWellFormedWriter.WriteString(String text) at System.Xml.Linq.ElementWriter.WriteStartElement(XElement e) at System.Xml.Linq.ElementWriter.WriteElement(XElement e) at System.Xml.Linq.XElement.WriteTo(XmlWriter writer) at System.Xml.Linq.XNode.GetXmlString(SaveOptions o) at Xamarin.Android.Tasks.ManifestDocument.<>c.b__920(XElement x) at System.Linq.Lookup2.Create[TSource](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer) at System.Linq.GroupedEnumerable3.GetEnumerator() at System.Linq.Enumerable.d17`2.MoveNext() at Xamarin.Android.Tasks.ManifestDocument.d92.MoveNext() at Xamarin.Android.Tasks.ManifestDocument.d92.MoveNext() at Xamarin.Android.Tasks.ManifestDocument.d92.MoveNext() at Xamarin.Android.Tasks.ManifestDocument.RemoveDuplicateElements() at Xamarin.Android.Tasks.ManifestDocument.Save(Action2 logCodedWarning, TextWriter stream, Boolean removeNodes) at Xamarin.Android.Tasks.ManifestDocument.Save(Action2 logCodedWarning, Stream stream, Boolean removeNodes) at Xamarin.Android.Tasks.ManifestDocument.SaveIfChanged(TaskLoggingHelper log, String filename) at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res) at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17 mycompany C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\tools\Xamarin.Android.Common.targets 1476

Steps to Reproduce

No idea.

Possibly create new Maui app, target Android, target latest OS version, target latest SDK.

Did you find any workaround?

No

Relevant log output

Severity    Code    Description Project File    Line    Suppression State
Error   XAGJS7004   System.ArgumentException: '', hexadecimal value 0x0C, is an invalid character.
   at System.Xml.XmlEncodedRawTextWriter.WriteAttributeTextBlock(Char* pSrc, Char* pSrcEnd)
   at System.Xml.XmlEncodedRawTextWriter.WriteString(String text)
   at System.Xml.XmlWellFormedWriter.WriteString(String text)
   at System.Xml.Linq.ElementWriter.WriteStartElement(XElement e)
   at System.Xml.Linq.ElementWriter.WriteElement(XElement e)
   at System.Xml.Linq.XElement.WriteTo(XmlWriter writer)
   at System.Xml.Linq.XNode.GetXmlString(SaveOptions o)
   at Xamarin.Android.Tasks.ManifestDocument.<>c.<ResolveDuplicates>b__92_0(XElement x)
   at System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.GroupedEnumerable`3.GetEnumerator()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at Xamarin.Android.Tasks.ManifestDocument.<ResolveDuplicates>d__92.MoveNext()
   at Xamarin.Android.Tasks.ManifestDocument.<ResolveDuplicates>d__92.MoveNext()
   at Xamarin.Android.Tasks.ManifestDocument.<ResolveDuplicates>d__92.MoveNext()
   at Xamarin.Android.Tasks.ManifestDocument.RemoveDuplicateElements()
   at Xamarin.Android.Tasks.ManifestDocument.Save(Action`2 logCodedWarning, TextWriter stream, Boolean removeNodes)
   at Xamarin.Android.Tasks.ManifestDocument.Save(Action`2 logCodedWarning, Stream stream, Boolean removeNodes)
   at Xamarin.Android.Tasks.ManifestDocument.SaveIfChanged(TaskLoggingHelper log, String filename)
   at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res)
   at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask()
   at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17 mycompany   C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\tools\Xamarin.Android.Common.targets    1476
jonathanpeppers commented 1 year ago

Is it an invalid character in your AndroidManifest.xml file?

If you could share a .binlog of the failing build, we can probably find the file path. (and maybe line number?)

https://aka.ms/binlog

microsoft-github-policy-service[bot] commented 1 year ago

Hi @blmiles. We have added the "need-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

blmiles commented 1 year ago

@jonathanpeppers - thanks for such a quick response!

This is the AndroidManifest.xml It is very short and I'm checked every line!

I'll get the binlog shortly.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mycompany.myapp" android:versionCode="16" android:versionName="7.0.0.0">
    <application android:allowBackup="true" android:supportsRtl="true" android:label="myapp" android:icon="@mipmap/icon"></application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.MANAGE_MEDIA" />
    <uses-sdk android:minSdkVersion="31" android:targetSdkVersion="33" />
    <queries>
        <intent>
            <action android:name="android.support.customtabs.action.CustomTabsService" />
        </intent>
    </queries>
</manifest>
blmiles commented 1 year ago

@jonathanpeppers

Is there any way I can send the buildlog to you directly without uploading here?

Thanks

jonathanpeppers commented 1 year ago

You could use the email on my GitHub profile instead. Thanks.

blmiles commented 1 year ago

Excellent, thanks so much! Buildlog sent...

blmiles commented 1 year ago

@jonathanpeppers

Found the issue. Sent email explanation...

jonathanpeppers commented 1 year ago

Can you share an example of what file was wrong? It feels like it didn't give you a line number + file name that you could double-click the error to see where the issue was.

blmiles commented 1 year ago

Morning,

Turns out one of the constants was being used in decoration on a class. [Activity(Label= Constants.MYAPPLABEL, NoHistory = true, LaunchMode = LaunchMode.SingleTop, Exported = true)]

Everywhere else I do something this within code: string MyAppLabel = XORService.XORCipher(Constants. MYAPPLABEL , Constants.XORKEY);

But it never cites the file, class or the line where the error occurred.

Yes, there's a build error msg that can be fixed/improved, BUT really my own error not paying attention :(

Hope that helps!

Let me know if you need anything else on this.

Thanks again Jonathan!

On Mon, Sep 18, 2023 at 10:18 PM Jonathan Peppers @.***> wrote:

Can you share an example of what file was wrong? It feels like it didn't give you a line number + file name that you could double-click the error to see where the issue was.

— Reply to this email directly, view it on GitHub https://github.com/xamarin/xamarin-android/issues/8349#issuecomment-1724732787, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGIKTCH6I4FUDT6KPHI4US3X3D6GLANCNFSM6AAAAAA45G7BT4 . You are receiving this because you were mentioned.Message ID: @.***>

jonathanpeppers commented 1 year ago

Can you share the value of Constants.MYAPPLABEL?

It sounds like [Activity(Label= "Something Invalid XML")] doesn't give a line number for the AndroidManifest.xml file. So, we could keep this open to look into in the future.

blmiles commented 1 year ago

Hi Jonathan,

Here it is: public const string MYAPPLABEL= "7\n\fC\a&\f\t\r\u00017\n\0\u000e\u001bm\u001b\u0004\0\0:\f\u0002\u0002\u0012 \a";

Hope that helps!

On Tue, Sep 19, 2023 at 9:41 AM Jonathan Peppers @.***> wrote:

Can you share the value of Constants.MYAPPLABEL?

It sounds like [Activity(Label= "Something Invalid XML")] doesn't give a line number for the AndroidManifest.xml file. So, we could keep this open to look into in the future.

— Reply to this email directly, view it on GitHub https://github.com/xamarin/xamarin-android/issues/8349#issuecomment-1725552902, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGIKTCE7HR4PJE6KS7ZXBBTX3GOITANCNFSM6AAAAAA45G7BT4 . You are receiving this because you were mentioned.Message ID: @.***>

blmiles commented 1 year ago

Actually, here's the whole file:

using Android.App; using Android.Content.PM;

namespace MyCompany;

[Activity(Label= Constants.MYAPPLABLE, NoHistory = true, LaunchMode = LaunchMode.SingleTop, Exported = true)] [IntentFilter(new[] { Android.Content.Intent.ActionView }, Categories = new[] { Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryBrowsable }, DataScheme = CALLBACK_SCHEME)] public class WebAuthenticationCallbackActivity : Microsoft.Maui.Authentication.WebAuthenticatorCallbackActivity { string CALLBACK_SCHEME = XORService.XORCipher(Constants. MYAPPLABLE, Constants.XORKEY), }

This actually works with the non-XOR'd value assigned to the Label. Part of my Auth0 authentication...

Thx,

Lindsay Miles

On Tue, Sep 19, 2023 at 9:41 AM Jonathan Peppers @.***> wrote:

Can you share the value of Constants.MYAPPLABEL?

It sounds like [Activity(Label= "Something Invalid XML")] doesn't give a line number for the AndroidManifest.xml file. So, we could keep this open to look into in the future.

— Reply to this email directly, view it on GitHub https://github.com/xamarin/xamarin-android/issues/8349#issuecomment-1725552902, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGIKTCE7HR4PJE6KS7ZXBBTX3GOITANCNFSM6AAAAAA45G7BT4 . You are receiving this because you were mentioned.Message ID: @.***>