Regression in mapping issues from autogenerated code to razor files in AdHoc workspaces
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
Hello!
We've identified a regression in the [sonar-dotnet analyzer ](https://github.com/SonarSource/sonar-dotnet) when it comes to issue location mapping from generated code to Razor files within adhoc workspaces after updating to .NET SDK 9.0.301.
Here's how the issue manifests:
From 8.0.5 up to 9.0.106
```csharp
The solution to all problems is: @(RaiseHere(21))
@*Correct locations*@@* ^^^^^^^^^ *@
@* ^^ Secondary@-1 *@
```
With 9.0.301
```csharp
The solution to all problems is: @(RaiseHere(21))
@*Wrong locations*@@* ^^^^^^^^^ *@
@* ^^ Secondary@-1 *@
```
It appears there's a change in the auto-generated code, as shown in the image below, which is causing the issue location to be shifted to the right.

Specifically, the issue location has been shifted right by the same number of characters as the `__builder.AddContent(2, ` length.
Based on our experiments, this problem doesn't seem to occur in non-adhoc workspaces (I'll update this ticket if we find new information).
One last question:
We've also noticed that issues previously present in MSBuild workspaces no longer exist (e.g., issue mapping for nested expressions, as seen [here](https://docs.google.com/presentation/d/1USIANRKqh3L1ol4ZbCbpGB8MatbaxGg4qcpRx8zc_So/edit?slide=id.g2b0d9e2336a_0_695#slide=id.g2b0d9e2336a_0_695)). One key difference is the use of enhanced line directives that include an offset. Does this offset now consistently match the user-written expression in the source files, or has something else changed? I am asking this because, based on [this comment](https://github.com/dotnet/roslyn/issues/69248#issuecomment-1749952541), my understanding is that this wasn't the case.
Regression Details:
You can see the details of this regression in these diffs: [here](https://github.com/SonarSource/sonar-dotnet/pull/9295/files#diff-4512c623568d2821fb0f97b8c9a811dfde9527f79d00603985ac32cbd90819c7L1) and [here](https://github.com/SonarSource/sonar-dotnet/pull/9295/files#diff-4512c623568d2821fb0f97b8c9a811dfde9527f79d00603985ac32cbd90819c7R1). These show that test issue locations that were fixed with .NET 8.0.5 have now reverted to being shifted.
Thanks a lot for your help!
Contributor guide
Assessment
This issue has not been assessed yet.