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.

Dotnet format fails with EnforceCodeStyleInBuild enabled in 7.0.200

See original GitHub issue

Describe the bug

When running dotnet format with .NET SDK 7.0.200 and EnforceCodeStyleInBuild, I get an error of Microsoft.CodeAnalysis 4.5.0.0 not being found. This works however on .NET SDK 7.0.103. It looks like the version of the Microsoft.CodeAnalysis within dotnet-format is incorrect (shipped with 4.4.0 while the SDK is expected 4.5.0), and additionally 4.5.0 is yet to be released on nuget.

To Reproduce

A new project with the csproj modified to have the property <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>. Here is a sample:

CodeAnalysisBug.zip

Exceptions (if any)

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
File name: 'Microsoft.CodeAnalysis, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at Microsoft.CodeAnalysis.DefaultAnalyzerAssemblyLoader.DirectoryLoadContext.Load(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)

Further technical details

.NET SDK: Version: 7.0.200 Commit: 534117727b

Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.200\

Host: Version: 7.0.3 Architecture: x64 Commit: 0a2bda10e8

.NET SDKs installed: 7.0.101 [C:\Program Files\dotnet\sdk] 7.0.102 [C:\Program Files\dotnet\sdk] 7.0.103 [C:\Program Files\dotnet\sdk] 7.0.200 [C:\Program Files\dotnet\sdk]

Issue Analytics

  • State:open
  • Created 7 months ago
  • Reactions:25
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
pzieziocommented, Mar 2, 2023

Did this solve the issue for you? I’m having the exact same issue, but was unable to resolve it by installing the Microsoft.CodeAnalysis.CSharp v4.5.0 package as suggested. The only solution so far has been to pin the SDK to 7.0.103.

I’m also stuck at 7.0.103 at the moment. Installing Microsoft.CodeAnalysis.CSharp v4.5.0.0 in every project is not a valid solution. At 7.0.103 dotnet format works without that.

6reactions
herebebeastiescommented, Mar 14, 2023

See:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why am I getting warnings that analysers are not found?
This is a Visual Studio issue caused by EnforceCodeStyleInBuild property in .csproj file (in combination with the preview version of .NET 7) ...
Read more >
dotnet format command - .NET CLI
The dotnet format command formats code to match EditorConfig settings for the current directory.
Read more >
Can the command dotnet format cause runtime errors?
I understand that there might be warnings that could be triggered by using "dotnet format" that could lead to build errors.
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