dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.84k stars 1.67k forks source link

XAML errors frequently do not reference the file with an issue #21038

Open BlueRaja opened 4 months ago

BlueRaja commented 4 months ago

Description

See title. Sometimes when there's an error with an XAML file, Visual Studio is unable to tell me which file/line the problem occurs in.

I never had this issue with Xamarin Forms, but in one week of Maui it's happened multiple times.

Steps to Reproduce

I'm not sure if this will reproduce the issue, but with the latest instance, I accidentally added the Spacing attribute to a StackLayout twice

<StackLayout HorizontalOptions="FillAndExpand" Spacing="0" Margin="5,0,5,0" Spacing="6">
    ...
</StackLayout>

The error in the error list opened up the .csproj file, rather than the file containing the error.

2024-03-06 01_20_08-NVIDIA GeForce Overlay DT

Link to public reproduction project repository

No response

Version with bug

8.0.3 GA

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

jfversluis commented 4 months ago

Reading the error message it specifies exactly where the error is: line 14, position 81

@mgoertz-msft is there something to be done on our side to also make the double-click work so people will go to the right position immediately or is that in VS?

mgoertz-msft commented 4 months ago

@jfversluis All XAML IntelliSense errors are prefixed with XLS (for XAML Language Service). These particular errors start with MAUIG, which come from the MAUI SourceGenerator. So this should probably be fixed there to not report the project as the file with the error in it.

BlueRaja commented 4 months ago

Reading the error message it specifies exactly where the error is: line 14, position 81

It claims the error is in the .csproj file. It gives no indication of which file actually contains the error.

jfversluis commented 4 months ago

It claims the error is in the .csproj file. It gives no indication of which file actually contains the error.

There column with that info does seem to have more text as it's ending in ... if you expand the column, is the right file in there?

BlueRaja commented 4 months ago

That column is expanded, as you can see in the screenshot. If I copy the full error from VS using "right-click + copy", I get this:

Severity    Code    Description Project File    Line    Suppression State   Details
Error   MAUIG1001   An error occured while parsing Xaml: 'Spacing' is a duplicate attribute name. Line 14, position 81..    Ringotan.KanjiControl (net8.0-android)  C:\Projects\CSharp\Ringotan\Ringotan.KanjiControl\Ringotan.KanjiControl.csproj  1   Active  
ninachen03 commented 3 months ago

Verified this issue on VS 17.10.0 Preview 2. can repro it. image

StephaneDelcroix commented 1 month ago

@mgoertz-msft could you help here ? The problem is at this line (I suspect)

var location = projItem.RelativePath is not null ? Location.Create(projItem.RelativePath, new TextSpan(), new LinePositionSpan()) : null;

RelativePath isn't null as a location is returned (position) but is probably string.Empty

mgoertz-msft commented 1 month ago

@StephaneDelcroix Those values come from here:

        fileOptions.TryGetValue("build_metadata.additionalfiles.TargetPath", out var targetPath);
        fileOptions.TryGetValue("build_metadata.additionalfiles.ManifestResourceName", out var manifestResourceName);
        fileOptions.TryGetValue("build_metadata.additionalfiles.RelativePath", out var relativePath);
        fileOptions.TryGetValue("build_property.targetframework", out var targetFramework);
        return new ProjectItem(additionalText, targetPath: targetPath, relativePath: relativePath, manifestResourceName: manifestResourceName, kind: kind, targetFramework: targetFramework);

If the values aren't right, then that's either not the correct way to retrieve them or there's a bug in Roslyn that doesn't populate those values as expected. Another question would be if this happens for all MAUI XAML files or just some? And if it's the latter then what's different about those?