Skip to content
New issue

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

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

Already on GitHub? # to your account

OmniSharp fails to load projects due to Microsoft.CodeAnalysis.CSharp.CodeStyle analyzer reference #2161

Closed
alexrp opened this issue May 25, 2021 · 6 comments

Comments

@alexrp
Copy link

alexrp commented May 25, 2021

  • OmniSharp: 1.37.10
  • .NET: 6.0.100-preview.4.21255.9

Loading one of my larger solutions results in the OmniSharp log being flooded with the following:

[fail]: OmniSharp.MSBuild.ProjectManager
        Failure while loading the analyzer reference 'Microsoft.CodeAnalysis.CSharp.CodeStyle': Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Unfortunately, it's going to be very hard to reduce this solution to a reasonable repro that I can post here so I'm hoping the error might ring a bell to someone.

@filipw
Copy link
Member

filipw commented May 25, 2021

OmniSharp does not support Microsoft.CodeAnalysis 4.x.x because it ships with its own 3.11.0-1.21262.10 this will converge in the future but for now it is too early for us to move to 4.

@alexrp
Copy link
Author

alexrp commented May 25, 2021

I'm not referencing that version of Microsoft.CodeAnalysis anywhere though. I have an analyzer project referencing 3.9.0 only.

@alexrp
Copy link
Author

alexrp commented May 25, 2021

I also have a project in the solution that uses RoslynCodeTaskFactory FWIW.

But what's weird is that if I disable the use of RoslynCodeTaskFactory and remove all analyzer references, I still get these errors.

I'm really not sure where the 4.x reference could be coming from.

@alexrp
Copy link
Author

alexrp commented May 26, 2021

Good news. I have a relatively simple project that repros the issue: https://github.com/alexrp/system-terminal

Just clone the master branch and open the folder in VS Code with the latest OmniSharp and .NET 6 Preview 4 installed. I assume this is happening (somehow) because this project uses Microsoft.CodeAnalysis.BannedApiAnalyzers. Projects that don't use external analyzers from NuGet have no issues.

@alexrp
Copy link
Author

alexrp commented May 26, 2021

Narrowed it down: EnforceCodeStyleInBuild=true seems to cause it.

I guess these analyzers are compiled against a newer Roslyn version. I've worked around this for now by doing:

        <EnforceCodeStyleInBuild Condition="'$(DesignTimeBuild)' != 'true'">true</EnforceCodeStyleInBuild>

@filipw
Copy link
Member

filipw commented Jun 21, 2021

Resolved by #2175

@filipw filipw closed this as completed Jun 21, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants