Search code examples
c#compiler-errorsmaui

Getting weird compiler error XAGAP7000 in my otherwise-simple C#/MAUI app


I have a simple C#/MAUI app - all classes in the same namespace. Getting this weird error XAGAP7000 all of a sudden, and Googling doesn't seem to help. I tried repairing the Visual Studio installation as well. Double-checked the XAML (see below). Totally flummoxed!

Severity    Code    Description Project File    Line    Suppression State
Error (active)  XAGAP7000   System.Xml.XmlException: The ':' character, hexadecimal value 0x3A, cannot be included in a name. Line 2, position 26.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.ParseAttributes()
   at System.Xml.XmlTextReaderImpl.ParseElement()
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlReader.MoveToContent()
   at Xamarin.Android.Tasks.GetAndroidPackageName.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 25 Calculator2 (net8.0-android)    C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.95\tools\Xamarin.Android.Common.targets    618 

But when you double-click on this error, it takes you to the first line of the snippet below in Xamarin.Android.Common.targets, where there's no ':' at all:

  <GetAndroidPackageName
      ManifestFile="$(_AndroidManifestAbs)"
      AssemblyName="$(AssemblyName)"
      ManifestPlaceholders="$(AndroidManifestPlaceholders)"
      PackageName="$(_AndroidPackage)">
    <Output TaskParameter="PackageName" PropertyName="_AndroidPackage" />
  </GetAndroidPackageName>
</Target>

Here's the top of my XAML:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:Adam"
             x:Class="Adam.MainPage"
             BackgroundColor="Black">
    
    <ContentPage.BindingContext>
        <local:AdamViewModel />
    </ContentPage.BindingContext>

Other than that, I'm styling my custom buttons:

   <Style TargetType="{x:Type local:Button2}">

And doing some commanding:

<local:Button2 (blah blah) Command="{Binding ButtonClick}" CommandParameter="A0" />

And that bound function is sitting in my ViewModel class.

Appreciate any thoughts on why Visual Studio 2022 hates me today.


Solution

  • So I resolved this issue in the end.

    No amount of solution cleaning, bin deleting, repairing, uninstalling etc. did anything at all.

    What did seem to work is creating a completely new solution, and copying all my code over. Then everything worked just fine. The next job is to change the namespace back to what it was, but at least it builds and runs correctly now.