dotnet / linker

388 stars 127 forks source link

dotnet format command broke when IsTrimmable is enabled #3064

Closed rodrigovaras closed 1 year ago

rodrigovaras commented 1 year ago

Description

dotnet format fails to run on a project that has IsTrimmable enabled. (It also happens on projects that have PublishAot enabled that implicitly enables IsTrimmable.)

This is happening on .NET 7 RC :7.0.100-rc.1.22431.12

Reproduction Steps

  1. dotnet new console
  2. add <IsTrimmable>true</IsTrimmable>
  3. dotnet format

Expected behavior

dotnet format runs fine

Actual behavior

dotnet format source\repos\NativeLibrary\NativeLibrary.csproj Unhandled exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Could not load file or assembly 'Microsoft.CodeAnalysis.Workspaces, Version=4.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified. Could not load file or assembly 'Microsoft.CodeAnalysis.Workspaces, Version=4.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified. Could not load file or assembly 'Microsoft.CodeAnalysis.Workspaces, Version=4.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified. Could not load file or assembly 'Microsoft.CodeAnalysis.Workspaces, Version=4.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified. C

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

dotnet-issue-labeler[bot] commented 1 year ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

jkotas commented 1 year ago

Edited description to have more minimal repro.

jkotas commented 1 year ago

dotnet format loads ILLink.CodeFix and calls Module.GetTypes to find all possible code fixers. dotnet-format comes with 'Microsoft.CodeAnalysis.Workspaces 4.3.0.0.ILLink.CodeFixdepends on 'Microsoft.CodeAnalysis.Workspaces 4.4.0.0. It results into the above exception to be thrown from Module.GetTypes call.

I assume that this version mismatch is fixed in the current .NET 7 build and further action is required. Correct?

marek-safar commented 1 year ago

@tlakollo does this sound familiar ?

/cc @sbomer

sbomer commented 1 year ago

Looks like this is fixed in rc2, where dotnet-format comes with Microsoft.CodeAnalysis.Workspaces 4.4.0.0.