maui icon indicating copy to clipboard operation
maui copied to clipboard

XAML errors frequently do not reference the file with an issue

Open BlueRaja opened this issue 1 year ago • 8 comments

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

BlueRaja avatar Mar 06 '24 09:03 BlueRaja

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?

jfversluis avatar Mar 06 '24 13:03 jfversluis

@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.

mgoertz-msft avatar Mar 06 '24 15:03 mgoertz-msft

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.

BlueRaja avatar Mar 07 '24 01:03 BlueRaja

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?

jfversluis avatar Mar 07 '24 07:03 jfversluis

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	

BlueRaja avatar Mar 07 '24 08:03 BlueRaja

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

ninachen03 avatar Mar 15 '24 07:03 ninachen03

@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

StephaneDelcroix avatar May 13 '24 13:05 StephaneDelcroix

@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?

mgoertz-msft avatar May 13 '24 20:05 mgoertz-msft