简体   繁体   中英

Could not load file or assembly 'Microsoft.CodeAnalysis, version= 1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependenc

An update occurred last night and now I find myself unable to do a ctrl + '.' for code suggestions in VS 2015. An error message comes up saying the following:

Could not load file or assembly 'Microsoft.CodeAnalysis, version= 1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

I can still build and develop but this will be really annoying without this feature. I admit it, I am getting soft!

Anyone have a suggestion for fixing this bug?

As pointed out by @CaptainAmerica the solution is to update the CodeDom assembly from NuGet. One should point out how to do this in Visual Studio. I found the solution here:

https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/

Basically, in the Visual Studio menu select:

Tools-> Nuget Package Manager -> Package Manager Console

In the console that appears at the bottom of Visual Studio run this command:

Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform

If any of the options doesn't work, here is the detailed guide to handle this scenario....

First of all version is important. Notice the version mentioned in the error...

Could not load file or assembly 'Microsoft.CodeAnalysis, version= 1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

If you see above error it means that it's not able to find version 1.3.1. Now please create new VS project. No preferences, it can be just simple console application. Now once project template is ready, go to Package Manager and run following command with your specified version...

Install-Package Microsoft.CodeAnalysis -Version 1.3.1

This will install all packages. Let it complete. Once it's done. We don't need this newly created project at all. You can delete it completely. Seriously! you can delete it. We did this because we wanted that package installed at global nuget level. When you install something, nuget stores it at global level of your machine as well. Path will be something like this...

C:\Users\<<Your Windows User>>\.nuget\packages

You can know your path by following...

%USERPROFILE%\.nuget\packages

Now you will see your required Microsoft.CodeAnalysis.dll there in following folder...

C:\Users\<<Your Windows User>>\.nuget\packages\Microsoft.CodeAnalysis.Common\1.3.1\lib\net45

Please note that above path contains version number (1.3.1). If your version is different, look into that version folder.

Now that you have dll with you, all that you need to do is add that dll to GAC. For that you will need GacUtil.exe

This file get installed along with Visual Studio already. You can search "GacUtil" in C drive. For me it's there on below path...

C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools

Now run command prompt as Administrator and navigate current directory to your path containing GacUtil. The run below command to install that dll in GAC.

gacutil
 -i C:\Users\<<You Windows User>>\.nuget\packages\Microsoft.CodeAnalysis.Common\1.3.1\lib\net45\Mi
crosoft.CodeAnalysis.dll

Basically providing path to dll we installed globally. It will show message on successful installation.

That's all! Now start your Visual Studio again and you will get this issue fixed.

I had the same problem with Visual Studio 2015 Update 2, to solve the problem globally for all solutions, update to Visual Studio 2015 Update 3 . Here is a link: Download from here

I found this page and at the bottom of the page under "Compatibility with ASP.NET" it says that ASP.NET uses the nuget package Microsoft.CodeDom.Providers.DotNetCompilerPlatform to update the Microsoft.CodeAnalysis assemblies. So I updated the DotNetCompilerPlatform package from 1.0.0 to 1.0.3 and it works again! Yeah, life is good again!

To solve this problem for all solutions, I needed to install the assembly Microsoft.CodeAnalysis.dll directly to the GAC – Global Assemblies Cache .

I got the file Microsoft.CodeAnalysis.dll from C:/Users/[user]/.nuget/packages/Microsoft.CodeAnalysis.Common/1.3.2/lib/portable-net45+win8/Microsoft.CodeAnalysis.dll .

To install the assembly to the GAC, I used a PowerShell script from https://github.com/LTruijens/powershell-gac .

Finally, I managed to install the assembly to the GAC with the following command from PowerShell:

Add-GacAssembly [myPath]\Microsoft.CodeAnalysis.dll

I was also facing same issue. My visual studio 2015 version was 2.0. I upgraded it to version 3.

Issue got solved !!!

I have solved the problem this way:

Update Visual studio 2015 to Update 3

from the menu chose View => Notifications => Visual Studio Update 3 and clicked the update button.

Today ! i got the same problem and i resolve it by restarting visual studio 2015 :)

I was also facing same issue, Try installing Microsoft.CodeAnalysis.CSharp nuget package. And if its not resolved, check version of Microsoft.Net.Compilers in your project, I was having version as 1.0.0 which was causing issue so updated Microsoft.Net.Compilers nuget to v1.3.2.

Found solution here : Github discussion

I fixed this issue by updating all Nuget Microsoft dependencies to v2.0.0. This was using VS 2017. I was using a preview version.

In my case, the error occurred after turning off Live Unit Testing and running tests manually.Some tests would fail with the above error message.

Going into Test --> Live Unit Testing --> Options and issuing "Delete Persisted Data" resolved the problem.

我通过删除位于解决方案中的 .vs 文件夹解决了类似的问题。

I found the missing assemblies in the NuGet package (After the first one was resolved there were mulitple otheres):https://www.nuget.org/packages/Microsoft.Net.Compilers/1.3.1-rc

Installed them using GacUtil from the Dev console.

Unfortunately the extensive solution with "nuget install/gacutil" here above couldn't work as the exact version of the dependency dll was not available.

The following solved my issue in our complex webform application was to perform within the solution in Visual Studio -> Tools -> Nuget -> console package manager

Update-Package -reinstall 

In my case, I was getting this error because my Visual Studio Solution was trying to use TextTransform.exe during a pre-build step in one of the projects, but my local machine didn't have the TextTransform.exe at the path specified by my pre-build step and my first attempt at fixing that was to just copy TextTransform.exe from some other location to where Visual Studio expected it to be. That appears to have caused this problem, because TextTransform.exe has other silent dependencies.

My fix was to change the pre-build steps so instead of looking for the file at

C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\14.0\TextTransform.exe

it would instead look in the Visual Studio install folder which had a bunch of other files, presumably one of which was a peer dependency of TextTransform.exe

C:\Program Files\Visual Studio\Common7\IDE\TextTransform.exe

That seemed to fix things for me.

I got the same problem, I am using VS2017 and installed Microsoft.EntityFrameworkCore.SqlServer 3.1.8, while in my VS2017 .Net core version is 2.1 So I downgraded my Microsoft.EntityFrameworkCore.SqlServer to 2.1.1 and restarted the solution.

The warning was gone !!

I had similar errors in VS2019 after upgrading project to .Net 5 according to https://docs.microsoft.com/en-us/aspnet/core/migration/31-to-50?view=aspnetcore-5.0&tabs=visual-studio .

error CS0006: Metadata file 'C:\\Users\\.nuget\\packages\\microsoft.codeanalysis.analyzers\\1.1.0\\analyzers\\dotnet\\cs\\Microsoft.CodeAnalysis.Analyzers.dll' could not be found.

'C:\\Users\\.nuget\\packages\\microsoft.codeanalysis.analyzers\\1.1.0\\analyzers\\dotnet\\cs\\Microsoft.CodeAnalysis.CSharp.Analyzers.dll' could not be founderror CS0006: Metadata file

The fix was to close and reopen VS 2019

I encountered this issue when trying to build someone's code from github. I was opening it in VS 2019 but I also have VS 2022. Opening and building in VS 2022 just worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question 'Could not load file or assembly 'Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies Could not load file or assembly 'Microsoft.Owin, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' Could not load file or assembly 'Microsoft.Owin, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 Could not load file or assembly 'Microsoft.Owin, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies Could not load file or assembly 'Microsoft.Data.OData, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies Could not load file or assembly 'WebGrease, Version=1.5.1.25624, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies Could not load file or assembly 'System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or Could not load file or assembly 'System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM