microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.36k stars 678 forks source link

XamlCompiler does not provide enough information to locate XML parse errors #7367

Closed jamers99 closed 1 year ago

jamers99 commented 2 years ago

Describe the bug

We're migrating from UWP to WinUI and a few of our files didn't have the following code in the .xaml.

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

If you remove them, it fails...

Task "CompileXaml"
1>    Xaml Compiler Marker: 9:03:58:  20 perfXC_StartPass1, General.WinUI
1>    Xaml Compiler Marker: 9:03:58:  73 perfXC_FingerprintCheck, Differ: c:\repos\eagle\framework\client\eagle.client.winui\bin\debug\net6.0-windows10.0.19041.0\eagle.client.winui.dll
1>    Xaml Compiler Marker: 9:03:58:  81 perfXC_FingerprintCheck, Reference Assemblies Fingerprint Changed
1>    Xaml Compiler Marker: 9:03:58:  81 perfXC_CreatingTypeUniverse
1>    Xaml Compiler Marker: 9:03:58:  81 perfXC_CreatedTypeUniverse
1>    Xaml Compiler Marker: 9:03:58:  81 perfXC_CreatingSchemaContext
1>    Xaml Compiler Marker: 9:03:58: 159 perfXC_InitializeTypeNameMapStart
1>    Xaml Compiler Marker: 9:03:59: 128 perfXC_InitializeTypeNameMapEnd
1>    Xaml Compiler Marker: 9:03:59: 157 perfXC_CreatedSchemaContext
1>    C:\Users\james\.nuget\packages\microsoft.windowsappsdk\1.0.3\buildTransitive\Microsoft.UI.Xaml.Markup.Compiler.interop.targets(475,9): Xaml Internal Error error WMC9999: 'd' is an undeclared prefix. Line 6, position 14.
1>       at System.Xml.XmlTextReaderImpl.Throw(Exception e)
1>       at System.Xml.XmlTextReaderImpl.LookupNamespace(NodeData node)
1>       at System.Xml.XmlTextReaderImpl.AttributeNamespaceLookup()
1>       at System.Xml.XmlTextReaderImpl.ParseAttributes()
1>       at System.Xml.XmlTextReaderImpl.ParseElement()
1>       at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
1>       at System.Xaml.XmlCompatibilityReader.Read()
1>       at MS.Internal.Xaml.Parser.XamlScanner.DoXmlRead()
1>       at MS.Internal.Xaml.Parser.XamlPullParser.<Parse>d__4.MoveNext()
1>       at MS.Internal.Xaml.NodeStreamSorter.StartNewNodeStreamWithSettingsPreamble()
1>       at MS.Internal.Xaml.NodeStreamSorter..ctor(XamlParserContext context, XamlPullParser parser, XamlXmlReaderSettings settings, Dictionary`2 xmlnsDictionary)
1>       at System.Xaml.XamlXmlReader.Initialize(XmlReader givenXmlReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
1>       at Microsoft.UI.Xaml.Markup.Compiler.Utilities.XamlNodeStreamHelper.ReadXClassFromXamlFileStream(TextReader fileStream, XamlSchemaContext schemaContext)
1>       at Microsoft.UI.Xaml.Markup.Compiler.SourceFileManager.PropagateOutOfDateStatus(DirectUISchemaContext context)
1>       at Microsoft.UI.Xaml.Markup.Compiler.CompileXamlInternal.DoExecute()
1>    Xaml Compiler Marker: 9:04:00:  27 perfXC_EndPass1, General.WinUI
1>  Done executing task "CompileXaml" -- FAILED.

But it gives no indication of where the issue is. When there is a project with 60+ xaml files, it's incredibly tedious to find where the issue is. I actually wrote a regex to find it :D

Steps to reproduce the bug

Download and build this simple project that has the line removed (don't open the xaml file). App1.zip

Expected behavior

It should give the file that the error is in and when double clicking the error, take me to the proper line.

Screenshots

image

NuGet package version

WinUI 3 - Windows App SDK 1.0.4

Windows app type

Device form factor

Desktop

Windows version

Windows 11 (21H2): Build 22000

Additional context

No response

jamers99 commented 2 years ago

Small .NET 6 console app that I used to find which file had the missing xmlns :D

using System.IO;
using System.Text.RegularExpressions;

var findD = new Regex(@"(?<!xmlns\:d.*)d\:", RegexOptions.Singleline);
foreach (var file in Directory.EnumerateFiles(".\\..\\", "*.xaml", SearchOption.AllDirectories))
{
    if (file.Contains("bin", StringComparison.OrdinalIgnoreCase))
        continue;

    var text = await File.ReadAllTextAsync(file);
    if (findD.IsMatch(text))
        Console.WriteLine(file);
}
jamers99 commented 2 years ago

Ran into a similar issue that it doesn't provide the location. Errors about duplicate xmlns in xaml files, when double clicked, don't take you to the error location, but instead to a .targets file... :(

image
krschau commented 2 years ago

Were you upgrading using a tool or otherwise updating your current project, or did you create a new project and bring your older code over?

If this is something lots of people will hit, we can include it in our migration documentation. I'll also add it to the list of error message we could improve.

jamers99 commented 2 years ago

We were just bringing things over manually. It's definitally a user error, but the issue is that it does not take you to the place it should. It's very difficult to find the issue among 60+ files.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.