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

23

103

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?

Lorica answered 1/3, 2017 at 16:4 Comment(3)
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!Nikola
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.Lorica
As pointed out by Vilhelm H. in VS: Tools-> Nuget Package Manager -> Package Manager Console and then Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Kinakinabalu
Z
33

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

Zeringue answered 4/3, 2017 at 13:25 Comment(3)
I am changing the correct answer to this answer because my original answer only fixed the current solution and not any other solution of mine. In my opinion this corrects the issue and is the answer that most people will want when looking for a solution to this bug. Thanks shopOff!Lorica
Update 3 10/10 fix. Wonder when this was introduced? It just started happening to me all of a sudden.Dietsche
It did not work for me, while the solution https://mcmap.net/q/209775/-could-not-load-file-or-assembly-39-microsoft-codeanalysis-version-1-3-1-0-culture-neutral-publickeytoken-31bf3856ad364e35-39-or-one-of-its-dependenc fixed the issue.Nauru
L
63

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
Luht answered 2/3, 2017 at 15:55 Comment(3)
This solves the problem, but I still don't understand why we need to add this package at all. Until today, Ctrl + '.' worked fine in all of our solutions, and we didn't have this package listed in any of their NuGet configurations. A Repair of the VS 2015 install didn't help, either.Nikola
Thanks a lot! This did it. Special thanks for providing the solution command to command. Saved me the hassle of reading more than absolutely required. ;)Kinakinabalu
This may or may not work, but it seems like a bad idea that, for Intellisense/CodeAnalysis to work in Visual Studio, that individual solutions need that NuGet Package. Updating to Update 3 works.Recreation
D
40

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.

Dinesh answered 24/5, 2017 at 7:43 Comment(6)
This worked a treat for me! The one consideration other answers don't seem to mention is to do this in a NEW project. Otherwise you add a ton of rubbish to your solution & possibly source control.Dornick
@GilesDMiddleton, Yes, very true! It's really important point worth following. Microsoft.CodeAnalysis is really huge bundle of dependencies and you don't want them to be installed under your working project by any means.Dinesh
thank you , that works. In my situation , it was 2 dlls I had to installed, and I had to restart PC to take effect.Backfill
This is a perfect solution. Thank you, man. I will add a line from another comment or question Add-GacAssembly [myPath]\Microsoft.CodeAnalysis.dll. And if you have not yet install Gac, then open Powershell in admin mode and type Install-Module -Name Gac, After this runs, you can check by typing Add-Gac and press tab it should complete the command and then add your pathPampuch
You saved me. Thanks! I spend almost whole day fix this issue, and finally.Heartless
BTW, I also need to install the Microsoft.CodeAnalysis.CSharp.dll in the GAC for sonarqube to analyze the project.Heartless
Z
33

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

Zeringue answered 4/3, 2017 at 13:25 Comment(3)
I am changing the correct answer to this answer because my original answer only fixed the current solution and not any other solution of mine. In my opinion this corrects the issue and is the answer that most people will want when looking for a solution to this bug. Thanks shopOff!Lorica
Update 3 10/10 fix. Wonder when this was introduced? It just started happening to me all of a sudden.Dietsche
It did not work for me, while the solution https://mcmap.net/q/209775/-could-not-load-file-or-assembly-39-microsoft-codeanalysis-version-1-3-1-0-culture-neutral-publickeytoken-31bf3856ad364e35-39-or-one-of-its-dependenc fixed the issue.Nauru
L
11

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!

Lorica answered 1/3, 2017 at 16:4 Comment(3)
I am having the same problem. Could you please explain how to update the Microsoft.CodeAnalysis assemblies?Flyleaf
@Flyleaf Read the answer below. In VS: Tools-> Nuget Package Manager -> Package Manager Console and then Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Kinakinabalu
Ok. I did it and it solved the problem, but only for the specific solution. If I open another solution the problem persists.Flyleaf
F
10

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
Flyleaf answered 3/3, 2017 at 22:15 Comment(4)
Great idea, though I didn't try it. This probably happens automatically when updating to Update 3. But this is a great middle-solution between going to Update 3 vs. doing this in every solution.Recreation
The link to Add-GacAssembly is a link to the documentation, not to the script. The linked project doesn't, hilariously, appear to include any actual scripts. Google knows where the script is, but all it does is print an error about how the script isn't digitally signed.Councillor
Anyway, for those who don't have a day or two to spend fighting battles with PowerShell, there's gacutil in VS Developer Command Prompt. You can use that to install the above assembly in the GAC. It didn't resolve the issue for me.Councillor
@EdPlunkett, see github.com/LTruijens/powershell-gac/blob/master/INSTALL.md on how to install the powershell moduleViccora
O
5

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

Oneida answered 30/3, 2020 at 9:45 Comment(3)
Microsoft.Net.Compilers is deprecated and has been replaced by Microsoft.Net.Compilers.ToolSetSilesia
This is it. Thank you. Very weird issue. One only needs to make sure you match your Core version (3.1 or 6 or newer).Salomone
Thank you for your service. Adding Microsoft.CodeAnalysis.CSharp fixed a similar issue for me that came up when going from net5->net6.Corinecorinna
G
3

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

Issue got solved !!!

Gretna answered 8/3, 2017 at 10:28 Comment(0)
M
2

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.

Melanochroi answered 15/6, 2017 at 17:34 Comment(0)
M
2

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

Mannequin answered 5/11, 2019 at 9:4 Comment(0)
E
1

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.

Exudation answered 4/1, 2022 at 18:5 Comment(0)
T
1

You need to install NuGet package Microsoft.Net.Compilers.Toolset, but make sure you match the right .NET version. In my case I was targeting netcoreapp3.1 so max version could be 4.0.1.

My root cause was for MassTransit analyzers nagging they cant find Microsoft.CodeAnalysis package, eg. An instance of analyzer MassTransit.Analyzers.AsyncMethodAnalyzer cannot be created.

Thrips answered 20/10, 2022 at 8:1 Comment(0)
D
0

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.

Demonize answered 22/9, 2017 at 13:35 Comment(0)
H
0

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.

Hubbell answered 17/4, 2018 at 14:17 Comment(0)
U
0

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

Uteutensil answered 11/2, 2019 at 8:51 Comment(0)
F
0

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.

Footton answered 8/5, 2019 at 6:16 Comment(0)
E
0

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 
Explode answered 20/6, 2019 at 3:30 Comment(0)
E
0

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.

Elwin answered 21/8, 2019 at 20:0 Comment(0)
S
0

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

Shalon answered 3/10, 2020 at 2:58 Comment(0)
R
0

I had similar errors in VS2019 after upgrading project to .Net 5 according to https://learn.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

Rident answered 1/10, 2021 at 23:46 Comment(0)
R
0

Try adding Nuget Package Microsoft.VisualStudio.Web.CodeGeneration.Design to your project

Robyn answered 14/4, 2022 at 9:53 Comment(0)
P
0

This question is many years old and the answers are all fairly old as well. I only recently ran into a similar-enough issue that I feel sharing my experience here (although potentially not complete) is relevant.

D:\Code\C#\sdkrazortest>dotnet --version
6.0.401

D:\Code\C#\sdkrazortest>dotnet new webapp -o webapp1
The template "ASP.NET Core Web App" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore/6.0-third-party-notices for details.

Processing post-creation actions...
Running 'dotnet restore' on D:\Code\C#\sdkrazortest\webapp1\webapp1.csproj...
  Determining projects to restore...
  Restored D:\Code\C#\sdkrazortest\webapp1\webapp1.csproj (in 102 ms).
Restore succeeded.



D:\Code\C#\sdkrazortest>cd webapp1

D:\Code\C#\sdkrazortest\webapp1>dotnet build
MSBuild version 17.3.1+2badb37d1 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
REWRITECSS : error :  [D:\Code\C#\sdkrazortest\webapp1\webapp1.csproj]
    An assembly specified in the application dependencies manifest (rzc.deps.json) was not found:
      package: 'Microsoft.CodeAnalysis.Common', version: '4.3.0-3.22415.1'
      path: 'lib/netcoreapp3.1/Microsoft.CodeAnalysis.dll'

Build FAILED.

REWRITECSS : error :  [D:\Code\C#\sdkrazortest\webapp1\webapp1.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:10.32

I originally tried loading packages like the top comments here had suggested and realized this issue started happening shortly after install .net core 6. After seeing some SO comments on dotnet-aspnet-codegenerator being version-specific I tried to create my netcore3.1 app using an older version of the dotnet cli via global.json:

D:\Code\C#\sdkrazortest>type global.json
{
  "sdk": {
    "version": "3.1.403"
  }
}
D:\Code\C#\sdkrazortest>dotnet new webapp -o webapp2
Getting ready...
The template "ASP.NET Core Web App" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore/3.1-third-party-notices for details.

Processing post-creation actions...
Running 'dotnet restore' on webapp2\webapp2.csproj...
  Determining projects to restore...
  Restored D:\Code\C#\sdkrazortest\webapp2\webapp2.csproj (in 187 ms).

Restore succeeded.


D:\Code\C#\sdkrazortest>cd webapp2

D:\Code\C#\sdkrazortest\webapp2>dotnet build
Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  webapp2 -> D:\Code\C#\sdkrazortest\webapp2\bin\Debug\netcoreapp3.1\webapp2.dll
  webapp2 -> D:\Code\C#\sdkrazortest\webapp2\bin\Debug\netcoreapp3.1\webapp2.Views.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:09.91

While this isn't an answer for the new templates not just working for me.. it might help someone potentially get "unstuck" or be the catalyst for someone providing a proper answer.

Perfecto answered 28/9, 2022 at 17:14 Comment(0)
H
0

I think one of the possible reasons for this issue could be the incompatibility of the .NET Framework and certain NuGet package. In my case I have .NET Core 3.1 and Testcontainers 2.4.0. The error does not happen on my local machine but it keeps showing up in my GitHub Actions remotely. It goes away after I downgrade Testcontainers to 2.3.0. Later the NuGet package AspNetCore.HealthChecks.EventStore 6.0.2 causes the same issue but that gets fixed in minutes rather than in hours :)

Holding answered 17/2, 2023 at 15:41 Comment(0)
D
0

I was also facing this issue on VS2022, upgrading to latest build helped me get over this problem.

Dillondillow answered 30/4, 2024 at 6:34 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.