dotnet / dotnet/maui

Warnings From Generated XAML Refer to a file the IDE cannot find

Open
#35,908 2 comments 1 reaction 0 assignees View on GitHub
area-xaml i/regression partner/syncfusion platform/android platform/windows regressed-in-11-preview1 s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

### Description

Generated XAML creates a warning, for example: `warning CS8622: Nullability of reference types...` (actually this particular warning is pretty easy to figure out and resolve, but it's an easy example). The build emits an error, like:
```
1>H:\Develop\Bugs\XamlGeneration\XamlGeneration\obj\Debug\net10.0-windows10.0.19041.0\win-x64\intermediatexaml\Microsoft.Maui.Controls.SourceGen\Microsoft.Maui.Controls.SourceGen.XamlGenerator\MainPage.xaml.xsg.cs(143,21,143,37): warning CS8622: Nullability of reference types in type of parameter 'sender' of 'void MainPage.OnCounterClicked(object sender, EventArgs e)' doesn't match the target delegate 'EventHandler' (possibly because of nullability attributes).
```
But clicking on the error does noting because the file `MainPage.xaml.xsg.cs` cannot be found. Adding
``` XAML
true
```

To the project file does not help, so I guess there are two bugs:
1. Displaying a message about a file then removing the file before the user can take action.
2. `EmitCompilerGeneratedFiles` set to true should retain the files whether or not they have warnings.

### Steps to Reproduce

1. Create a new MAUI app
2. Edit `MainPage.xaml.cs` OnCounterClicked to specify the first parameter as `object sender` by removing the "?"
3. Build it and observe the warning in the build output

I'm sure this (clicking on a warning) used to work in .NET 10 but I'm not sure if it ever worked in .NET11.

### Link to public reproduction project repository

_No response_

### Version with bug

11.0.0-preview.4

### Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

### Last version that worked well

10.0.70

### Affected platforms

Windows, Android, I was *not* able test on other platforms

### Affected platform versions

Windows 11, Android SDK 35

### Did you find any workaround?

_No response_

### Relevant log output

```shell

```

Contributor guide

Open the contributing guide

Research direction

Reproduce the warning in a new MAUI app by changing MainPage.xaml.cs and inspect the generated intermediatexaml path and build output. Start by tracing how MainPage.xaml.xsg.cs is emitted and reported, including the project file's EmitCompilerGeneratedFiles setting; done means clicking the warning reaches usable source and generated files are retained when requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.