83
votes

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?

16
I'm getting this today as well...I wish I knew what broke it! Our build machine has the same VS/C# versions and its Ctrl+'.' still works fine. We never had DotNetCompilerPlatform in any of our projects' NuGet packages, so I don't understand why we suddenly need to install it and update all our projects' build configs!System.Cats.Lol
Sorry, not sure why this is happening.I just tried loading the Microsoft.CodeDom.Providers.DotNetCompilerPlatform on another project that didn't originally have it in the solution and it didn't work.Captain America
As pointed out by Vilhelm H. in VS: Tools-> Nuget Package Manager -> Package Manager Console and then Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Sven M.

16 Answers

29
votes

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

62
votes

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
35
votes

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.

11
votes

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!

9
votes

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
3
votes

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

Issue got solved !!!

2
votes

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.

1
votes

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

1
votes

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

0
votes

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.

0
votes

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.

0
votes

I fixed similar issue by deleting the .vs folder located inside the solution.

0
votes

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.

0
votes

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 
0
votes

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.

0
votes

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 !!