question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Logging Source Generator emits CS0757 errors when referencing Microsoft.Extensions.Telemetry

See original GitHub issue

Description

I have a number of applications, both public and private, where for test purposes I’ve set them up to ingest changes from the .NET daily builds feed out of the dotnet/installer repo.

For one specific application, updating to .NET 8 RC1 daily builds is causing the application to fail to compile due to CS0757 errors for duplication partial logger method implementations. We use this pattern in many of the applications ingesting daily builds, but only this application was affected.

Through trial and error of cutting back the application to a minimal repro, I’ve found that this issue is caused when the application references the Microsoft.Extensions.Telemetry NuGet package (it doesn’t even need to be used).

A repository that contains the subset of the application that causes the compilation error can be found at martincostello/CS0757-With-Telemetry-Repro.

Reproduction Steps

  1. Install version 8.0.100-rc.1.23412.1 of the .NET SDK.
  2. Clone https://github.com/martincostello/CS0757-With-Telemetry-Repro
  3. Run dotnet build /p:IncludeTelemetry=true

Expected behavior

The application compiles.

Actual behavior

The application fails to compile due to CS0757 errors:

> dotnet build /p:IncludeTelemetry=true
MSBuild version 17.8.0-preview-23401-01+b3989dc43 for .NET
  Determining projects to restore...
  Restored src\MyApplication\MyApplication.csproj (in 869 ms).
src\MyApplication\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(15,40): error CS0757: A partial method may not have multiple implementing declarations [src\MyApplication\MyApplication.csproj]
src\MyApplication\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(27,40): error CS0757: A partial method may not have multiple implementing declarations [src\MyApplication\MyApplication.csproj]
src\MyApplication\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(39,40): error CS0757: A partial method may not have multiple implementing declarations [src\MyApplication\MyApplication.csproj]
src\MyApplication\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(51,40): error CS0757: A partial method may not have multiple implementing declarations [src\MyApplication\MyApplication.csproj]
src\MyApplication\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(63,40): error CS0757: A partial method may not have multiple implementing declarations [src\MyApplication\MyApplication.csproj]

Build FAILED.

src\MyApplication\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(15,40): error CS0757: A partial method may not have multiple implementing declarations [src\MyApplication\MyApplication.csproj]
src\MyApplication\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(27,40): error CS0757: A partial method may not have multiple implementing declarations [src\MyApplication\MyApplication.csproj]
src\MyApplication\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(39,40): error CS0757: A partial method may not have multiple implementing declarations [src\MyApplication\MyApplication.csproj]
src\MyApplication\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(51,40): error CS0757: A partial method may not have multiple implementing declarations [src\MyApplication\MyApplication.csproj]
src\MyApplication\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(63,40): error CS0757: A partial method may not have multiple implementing declarations [src\MyApplication\MyApplication.csproj]
    0 Warning(s)
    5 Error(s)

Time Elapsed 00:00:02.65

Regression?

Worked with version 8.0.100-preview.7.23376.3 of the SDK.

Known Workarounds

Do not reference Microsoft.Extensions.Telemetry.

Configuration

  • .NET SDK 8.0.100-rc.1.23412.1
  • Microsoft.Extensions.Telemetry 8.0.0-rc.1.23409.4

Other information

It might be that this is caused by some sort of compiler/tooling lag between the runtime, extensions sdk and/or installer repos that will resolve itself over time as dependencies flow and is a non-issue in practice, but it’s been broken in this application since last week so I thought it was worth flagging.

Issue Analytics

  • State:open
  • Created a month ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
joperezrcommented, Aug 14, 2023

Thanks a bunch for the help @martincostello! This should have been fixed with: https://github.com/dotnet/extensions/pull/4238, but after some testing I can see that this is indeed still broken for web projects (since the package is correctly removing the Logging.Abstractions analyzer package, but the web project targeting pack also includes this analyzer so it has to be removed from there as well). I’ll put up a fix that addresses this and let you know when we have a package version for you to test

1reaction
joperezrcommented, Aug 18, 2023

Yeah, I think it should get backported. I’ll send out the PR for that in a bit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Logging Source Generator emits CS0757 errors when ...
Through trial and error of cutting back the application to a minimal repro, I've found that this issue is caused when the application...
Read more >
Microsoft.Extensions.Logging.Generators.dll: Could not ...
Created a project with Microsoft .Net Core 3.1 in Visual Studio Enterprise Version 16.11.8 Warning CS8032 An instance of analyzer Microsoft.
Read more >
Compile-time logging source generation - .NET
The source generator is triggered when LoggerMessageAttribute is used on partial logging methods. When triggered, it is either able to ...
Read more >
Application Insights logging with .NET - Azure Monitor
In this article, you learn how to capture logs with Application Insights in .NET apps by using the Microsoft.Extensions.Logging.
Read more >
Change the default output location for LoggingMessage ...
I'm using Rider and currently the output is being emitted to C:\Users<user.name>\AppData\Local\Temp\RiderSourceGeneratedDocuments<RandomId>\ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found