Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet format is broken on sdk 7.0.200 if EnforceCodeStyleInBuild is set to true – Could not load file or assembly 'Microsoft.CodeAnalysis' #1800

Closed
askazakov opened this issue Feb 15, 2023 · 28 comments
Assignees

Comments

@askazakov
Copy link

step to reproduce

  • create new project
dotnet new console
  • add <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> to .csproj

  • add global.json

dotnet new globaljson
  • change sdk version in global.json to "7.0.103"
  • run
dotnet format

everything is ok here.

  • change sdk version in global.json to "7.0.200"
  • run
dotnet format

and now there are a lot of

Unhandled exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

in output

@askazakov
Copy link
Author

dotnet --info
.NET SDK:
 Version:   7.0.200
 Commit:    534117727b

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  13.2
 OS Platform: Darwin
 RID:         osx.13-x64
 Base Path:   /usr/local/share/dotnet/sdk/7.0.200/

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

@askazakov askazakov changed the title dotnet format is broken on sdk 7.0.200 if EnforceCodeStyleInBuild is set to true dotnet format is broken on sdk 7.0.200 if EnforceCodeStyleInBuild is set to true – Could not load file or assembly 'Microsoft.CodeAnalysis Feb 15, 2023
@askazakov askazakov changed the title dotnet format is broken on sdk 7.0.200 if EnforceCodeStyleInBuild is set to true – Could not load file or assembly 'Microsoft.CodeAnalysis dotnet format is broken on sdk 7.0.200 if EnforceCodeStyleInBuild is set to true – Could not load file or assembly 'Microsoft.CodeAnalysis' Feb 15, 2023
craigktreasure added a commit to craigktreasure/SlnUp that referenced this issue Feb 15, 2023
As usual, `dotnet format` is broken on .NET 7.0.200 (see
dotnet/format#1800). We'll install the latest
of 7.0.100 for now.
@tidusjar
Copy link

Same is happening for me and all of my colleagues

.NET SDK:
 Version:   7.0.200
 Commit:    534117727b

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 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

@si618
Copy link

si618 commented Feb 20, 2023

Thanks for the heads-up, confirmed and if nothing else a good excuse to move to Directory.Build.Props

@zh6335901
Copy link

I had the same problem

@m3nax
Copy link

m3nax commented Feb 23, 2023

Same here

@panicoenlaxbox
Copy link

Idem, with dotnet --version 7.0.200.
@si618 Have I understood that there is workaround with Directory.Build.props? I've tried it and it doesn't work either.
Thank you.

@si618
Copy link

si618 commented Feb 27, 2023

@si618 Have I understood that there is workaround with Directory.Build.props? I've tried it and it doesn't work either. Thank you.

Commenting out EnforceCodeStyleInBuild as per linked commit worked for me.

Not really a workaround per se, just skipping until fixed, but having it in Directory.Build.props means only changing one file.

@panicoenlaxbox
Copy link

Ok, thank you, I hope it will be fixed soon.

@RikkiGibson RikkiGibson self-assigned this Feb 28, 2023
@RikkiGibson
Copy link
Contributor

I suspect that this is caused by dotnet-format's reference to the compiler getting out of date. #1782

@glen-84
Copy link

glen-84 commented Mar 24, 2023

@RikkiGibson Do you know if there are plans to assign a new maintainer to this project?

@MrcnPnkrsk
Copy link

Is there any Road Map for fixing this issue?

.NET 7.0.4 is installed automatically with Visual Studio 2022 and for the past 4 months bundled dotnet-format is unusable.
#1782 Seems to be forgotten.

@GGG-KILLER
Copy link

I've been getting this using .NET 8 in a dev container where .NET was installed using dotnet-install.sh.

The project it runs into an exception while trying to format is an Incremental Source Generator.

Solution: https://github.com/LorettaDevs/Loretta (devcontainer files are contained within)
Project: Loretta.Generators.SyntaxFactsGenerator
Format command: dotnet format (v8.0.405501+2cb3e68c6b9a966114572fd63f2a20d2cb54a288)
Output: https://gist.github.com/GGG-KILLER/81a9773f7c02a12a841edd331751d2ee

dotnet --info
$ dotnet --info
.NET SDK:
 Version:   8.0.100-preview.2.23157.25
 Commit:    54801b2435

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  22.04
 OS Platform: Linux
 RID:         ubuntu.22.04-x64
 Base Path:   /usr/local/dotnet/current/sdk/8.0.100-preview.2.23157.25/

Host:
  Version:      8.0.0-preview.2.23128.3
  Architecture: x64
  Commit:       30b879924a

.NET SDKs installed:
  6.0.407 [/usr/local/dotnet/current/sdk]
  7.0.202 [/usr/local/dotnet/current/sdk]
  8.0.100-preview.2.23157.25 [/usr/local/dotnet/current/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.15 [/usr/local/dotnet/current/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.4 [/usr/local/dotnet/current/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.0-preview.2.23153.2 [/usr/local/dotnet/current/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.15 [/usr/local/dotnet/current/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.4 [/usr/local/dotnet/current/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.0-preview.2.23128.3 [/usr/local/dotnet/current/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Apr 7, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Apr 11, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Apr 12, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
@avidenic
Copy link

avidenic commented Apr 14, 2023

This seems to be an issue on 7.0.202 and 7.0.203 as well.

TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Apr 14, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Apr 15, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Apr 15, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
@arunchndr
Copy link
Member

Thanks for that! Is there any way to get automated tests for this? I think this is the second or third time dotnet format has broken completely since 6.0 for roughly the same reason.

Absolutely yes for the integration test gap that needs to be filled. @sharwell to comment on the global json support.

@sharwell
Copy link
Member

dotnet format runs from a self-contained folder on disk. Whatever code dotnet uses to determine the binary to run for the format command is what determines the SDK that provides the format implementation. This seems like a question for the dotnet CLI about why it isn't accounting for global.json.

@JoeRobich
Copy link
Member

JoeRobich commented May 26, 2023

MSBuildLocator should be returning the pinned SDK first, if it was installed.

var msBuildInstance = Build.Locator.MSBuildLocator.QueryVisualStudioInstances()
.Where(instance => instance.Version.Major >= 6)
.FirstOrDefault();

Ideally, since the CLI launches the dotnet-format tool from the globla.json pinned SDK folder and the SDK has a particular layout, the tool would be updated to find the proper MSBuild using relative paths.

JohnnyCrazy added a commit to JohnnyCrazy/SpotifyAPI-NET that referenced this issue May 27, 2023
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue May 28, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue May 28, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Jun 4, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Jun 4, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
rajsite pushed a commit to ni/nimble that referenced this issue Jun 6, 2023
# Pull Request

## 🤨 Rationale

#1280 

## 👩‍💻 Implementation

It looks like a the build agent began pulling in a new version of the
.NET tools. `dotnet --info` prints out this for the CI build:
```
.NET SDKs installed:
  6.0.408 [/usr/share/dotnet/sdk]
  7.0.105 [/usr/share/dotnet/sdk]
  7.0.203 [/usr/share/dotnet/sdk]
  7.0.302 [/usr/share/dotnet/sdk]
```
So I'm guessing that 7.0.302 is causing issues.

I found
[dotnet/format#1800](dotnet/format#1800) which
is pretty close to what we're seeing. [This
comment](dotnet/format#1800 (comment))
makes it sound like there'll be a newer 7.0.3xx version that will fix
this problem, but the issue is still open so I guess that version isn't
out yet.
Also see
[dotnet/format#1834](dotnet/format#1834) and
[dotnet/sdk#32598](dotnet/sdk#32598) which
reference 7.0.302 and the DLL v4.6.0.0 specifically.

Changes in this PR:
- Re-enable Blazor C# linting in package.json
- Add a
[global.json](https://learn.microsoft.com/en-us/dotnet/core/tools/global-json)
file to ensure the `dotnet` commands are using .NET 6.0.xxx tooling.
- This will ensure both the CI and local builds are using the .NET 6 SDK
for the `dotnet` CLI commands
- Add a pipeline step to print out `dotnet --info`, which will print out
all the installed .NET SDK versions, which should make it easier to
debug issues like this in the future
- Update docs to explicitly call out that a .NET SDK install `6.0.202 <=
v < 7` is required
- Update the CI build (`main.yml`) `setup-dotnet` action to refer to
global.json to get the required .NET version to install (so we're not
encoding the required version in multiple places in code)

## 🧪 Testing

CI build + re-built locally.

## ✅ Checklist

- [x] I have updated the project documentation to reflect my changes or
determined no changes are needed.
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Jun 12, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Jun 12, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Jun 12, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
@idilov
Copy link

idilov commented Jun 14, 2023

Both this problem and dotnet/sdk#32598 seem to have been fixed in sdk 7.0.304.
I re-enabled EnforceCodeStyleInBuild, removed all workarounds and downgrades which I had been using for 4 months and can once again enjoy dotnet format as is. Hope it's not just me. Thank you!

TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Jun 14, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
@brminnick
Copy link

Both this problem and dotnet/sdk#32598 seem to have been fixed in sdk 7.0.304.

Awesome!! Yup, I can confirm that we can now use dotnet format again with no errors in our .NET Community Toolkit libraries

@JoeRobich
Copy link
Member

@brminnick Thanks for the confirmation! Closing.

TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Jun 16, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Jun 21, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Jun 23, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Jun 24, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Jun 26, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Jul 16, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Jul 16, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
TSRBerry added a commit to TSRBerry/Ryujinx that referenced this issue Jul 22, 2023
This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800
jcm93 pushed a commit to jcm93/Ryujinx that referenced this issue Aug 15, 2023
* Add workflow to perform automated checks for PRs

* Downgrade Microsoft.CodeAnalysis to 4.4.0

This is a workaround to fix issues with dotnet-format.
See:
- dotnet/format#1805
- dotnet/format#1800

* Adjust editorconfig to be more compatible with Ryujinx code-style

* Adjust .editorconfig line endings to match .gitattributes

* Disable 'prefer switch expression' rule

* Remove naming styles

These are the default rules, so we don't need to override them.

* Silence IDE0060 in .editorconfig

* Slightly adjust .editorconfig

* Add lost workflow changes

* Move .editorconfig comment to the top

* .editorconfig: private static readonly fields should be _lowerCamelCase

* .editorconfig: Remove alignment for declarations as well

* editorconfig: Add rule for local constants

* Disable CA1822 for HLE services

* Disable CA1822 for ViewModels

Bindings won't work with static members, but this issue is silently ignored.

* Run dotnet format for the whole solution

* Check result code of SDL_GetDisplayBounds

* Fix dotnet format style issues

* Add missing trailing commas

* Update Microsoft.CodeAnalysis.CSharp to 4.6.0

Skipping 4.5.0 since it breaks dotnet format

* Restore old default naming rules for dotnet format

* Add naming rule exception for CPU tests

* checks: Include all files before excluding paths

* Fix dotnet format issues

* Check dotnet format version

* checks: Run dotnet format with severity info again

* checks: Disable naming style rules until they won't crash the process anymore

* Remove unread private member

* checks: Attempt to run analyzers 3 times before giving up

* checks: Enable naming style rules again with the new retry logic
awesomesmallwolf added a commit to awesomesmallwolf/Spotify-API-By-NET that referenced this issue Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests