Stack frames are sometimes missing location in source generators

Open
#111,762 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
compilers

Research direction

Start with ProtocolGenerator.cs at lines 757 and 811, and the consuming Kafka.Protocol.csproj at line 42. Reproduce with Visual Studio 17.12.0 or the .NET CLI 8.0.404 by compiling twice without changes, then once after changing the generator. Done means stack-frame locations remain present on repeated unchanged compilations.

Written by the indexing model from the issue text.

Description

area-Diagnostics-coreclr needs-further-triage

Version Used:
Compiler version: '4.12.0-3.24523.10 (16f58fa3)'. Language version: 12.0.

I have written a source generator that tries to catch unhandled exceptions when generating code and output it through diagnostics. This works pretty good, disregarding the shortcomings of the Visual Studio Error List and description and messageFormat.

Image

But when compiling again with no changes, the location of the stackframes in the stacktrace of the exception is gone.

Image

If the registered source output changes then the location is reported again on next compilation.

Steps to Reproduce:

  1. Throw an exception here: https://github.com/Fresa/Kafka.Protocol/blob/e8a776639f7b8143fcfb006d01f7a2eef326c5be/Kafka.Protocol.SourceGenerator/ProtocolGenerator.cs#L757
  2. Attach a debugger here: https://github.com/Fresa/Kafka.Protocol/blob/e8a776639f7b8143fcfb006d01f7a2eef326c5be/Kafka.Protocol.SourceGenerator/ProtocolGenerator.cs#L811
  3. Compile once (here's a project using the generator) -> stack frame has location.
  4. Compile again -> stack frame is missing location.
  5. Change anything in the method at 1. and compile again -> stack frame has location again.

I've tested both in Visual Studio (Version 17.12.0) and the dotnet cli (8.0.404) with the same behavior.

Diagnostic Id: N/A

Expected Behavior:
Stack frame location is the same when no code changes.

Actual Behavior:
Stack frame location is missing when running the source generator multiple times with no changes.

Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.