postsharp / Metalama

Metalama is a Roslyn-based meta-programming framework. Use this repo to report bugs or ask questions.
164 stars 4 forks source link

1 error and 2 warnings after upgrading from 2024.0.7 to 2024.1.21 #310

Closed XtroTheArctic closed 3 weeks ago

XtroTheArctic commented 4 weeks ago

The error is new after the upgrade. I'm not sure about the warnings. They may have been there before the upgrade but I don't remember seeing them last time I made a change in my project many months ago. I would have reported them if I had seen.

Also, I can't find the location of the Metalama log file so I can't attach it here. Sorry.

Severity    Code    Description Project File    Line    Suppression State   Details
Error   CS8784  Generator 'MetalamaSourceGenerator' failed to initialize. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'MissingMethodException' with message 'Method not found: 'Microsoft.CodeAnalysis.IncrementalValueProvider`1<System.Collections.Immutable.ImmutableArray`1<!!0>> Microsoft.CodeAnalysis.IncrementalValueProviderExtensions.Collect(Microsoft.CodeAnalysis.IncrementalValuesProvider`1<!!0>)'.'.
System.MissingMethodException: Method not found: 'Microsoft.CodeAnalysis.IncrementalValueProvider`1<System.Collections.Immutable.ImmutableArray`1<!!0>> Microsoft.CodeAnalysis.IncrementalValueProviderExtensions.Collect(Microsoft.CodeAnalysis.IncrementalValuesProvider`1<!!0>)'.
   at Metalama.Framework.DesignTime.SourceGeneration.BaseSourceGenerator.Microsoft.CodeAnalysis.IIncrementalGenerator.Initialize(IncrementalGeneratorInitializationContext context)
   at Metalama.Framework.CompilerExtensions.MetalamaSourceGenerator.Initialize(IncrementalGeneratorInitializationContext context)
   at Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsCore(Compilation compilation, DiagnosticBag diagnosticsBag, CancellationToken cancellationToken)
-----
    Atesh.Metalama  E:\Projects\Atesh.Metalama\Atesh.Metalama\Atesh.Metalama.csproj 1   Active  

Severity    Code    Description Project File    Line    Suppression State   Details
Warning CS8032  An instance of analyzer Metalama.Framework.CompilerExtensions.MetalamaDiagnosticAnalyzer cannot be created from C:\Users\Onur\.nuget\packages\metalama.framework\2024.1.21\analyzers\dotnet\cs\Metalama.Framework.CompilerExtensions.dll: Method 'get_SupportedDiagnostics' in type 'Metalama.Framework.CompilerExtensions.MetalamaDiagnosticAnalyzer' from assembly 'Metalama.Framework.CompilerExtensions, Version=2024.1.21.0, Culture=neutral, PublicKeyToken=772fca7b1db8db06' does not have an implementation..   Atesh.Metalama  C:\Users\Onur\.nuget\packages\metalama.framework\2024.1.21\analyzers\dotnet\cs\Metalama.Framework.CompilerExtensions.dll    1   Active  

Severity    Code    Description Project File    Line    Suppression State   Details
Warning CS8032  An instance of analyzer Metalama.Framework.CompilerExtensions.MetalamaDiagnosticSuppressor cannot be created from C:\Users\Onur\.nuget\packages\metalama.framework\2024.1.21\analyzers\dotnet\cs\Metalama.Framework.CompilerExtensions.dll: Method 'get_SupportedSuppressions' in type 'Metalama.Framework.CompilerExtensions.MetalamaDiagnosticSuppressor' from assembly 'Metalama.Framework.CompilerExtensions, Version=2024.1.21.0, Culture=neutral, PublicKeyToken=772fca7b1db8db06' does not have an implementation..  Atesh.Metalama  C:\Users\Onur\.nuget\packages\metalama.framework\2024.1.21\analyzers\dotnet\cs\Metalama.Framework.CompilerExtensions.dll    1   Active  
XtroTheArctic commented 4 weeks ago

Github formatted my post in a weird way. I didn't apply any formatting. It was a pure wall of text. FYI.

svick commented 3 weeks ago

Is it possible that you updated some Metalama packages, but not all of them, or something like that? Can you share your csproj?

Thanks.

XtroTheArctic commented 3 weeks ago

Hello.

There is only one package reference in this project. The source code is here: https://bitbucket.org/XtroTheArctic/atesh.metalama/src/develop/

Gael and Daniel Balas still have access. If you tell me your email address, I can give you access too.

svick commented 3 weeks ago

I can access the repo, it seems it's public. But I can't reproduce the issue.

Does the error show up when you build the project? Or does build succeed, but the error only shows in the Visual Studio error window?

XtroTheArctic commented 3 weeks ago

Oh yea. That repo is open-source. I forgot.

The error is only in the error window. The build works fine but I didn't trust it because the error clearly says "It will not contribute to the output".

The error shows up as soon as I update the Metalama package.

Can you not repro?

Is there a cache folder I need to clean or something?

svick commented 3 weeks ago

The error is only in the error window. The build works fine but I didn't trust it because the error clearly says "It will not contribute to the output".

This problem only happens inside Visual Studio, and since build is mostly independent, it shouldn't be affected. So there's no reason not to trust it.

Can you not repro?

I can't repro, so I'm going to need more information from you, but it's going to be a bit involved, see below.

Is there a cache folder I need to clean or something?

I don't think so. Right now I can't think how that would help.


So, the problem is related to assembly loading in the ServiceHub.RoslynCodeAnalysisService process, which means to get more information you need to do the following:

  1. Install the dotnet-trace tool by executing dotnet tool install --global dotnet-trace on the command line.
  2. Remove the Metalama.Framework package from your project (e.g. by commenting out the relevant line in the csproj) and close VS.
  3. Start VS and open your project.
  4. Find the PID of the ServiceHub.RoslynCodeAnalysisService.exe process. You can use for example the Details tab of Task Manager for that.
  5. Execute dotnet-trace collect --providers Microsoft-Windows-DotNETRuntime:4 --process-id <pid>, replace <pid> by the PID you found in the previous step and let the command run. (Here's more information in case you're curious.)
  6. Re-add the Metalama.Framework package to your project in VS and open a C# file so that the error shows up.
  7. Stop dotnet-trace by pressing Enter or Ctrl+C.
  8. Send us the resulting .nettrace file.

Thanks.

XtroTheArctic commented 3 weeks ago

Here you go.

ServiceHub.RoslynCodeAnalysisService.exe_20240611_084913.zip

svick commented 3 weeks ago

Thanks.

Based on that trace, it seems we have introduced a compatibility issue with older versions of VS in Metalama 2024.0.13 and 2024.1.19.

What version of VS are you using?

We will be working on a fix, but in the meantime, using Metalama 2024.1.18 or upgrading to VS 17.10 should work around the issue.

XtroTheArctic commented 3 weeks ago

Oh, I see. My VS is 17.8.1.

I'll upgrade it and try soon. Thank you.

XtroTheArctic commented 3 weeks ago

The error and the warnings are gone with the latest VS version. Thank you.

prochan2 commented 3 weeks ago

The bug has been fixed in Metalama 2024.0.16 and 2024.1.22, and will be fixed in the next version of 2024.2 soon.