How to solve – Could not find a part of the path bin roslyn csc.exe error

If you are trying to run ASP.NET application and getting "bin\roslyn\csc.exe not found!" error in your browser even after successfully build and compile.

Don’t worry! this is all happening because your project is trying to find \bin\roslyn\csc.exe path inside your project at run time. The following packages have been added to your project. Just review yourpackages.config file, where you can find both of them as listed below.

Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Microsoft.Net.Compilers

Why Roslyn and what is the use of Roslyn in Visual Studio

If you are running your project using .net Framework 4.5.2 or higher version with Visual Studio 2015/2017/2019, you might have noticed that the project templates using Roslyn by default. Actually, Roslyn provides open-source C# and Visual Basic compilers with rich code analysis APIs. It enables building code analysis tools with the same APIs that are used by Visual Studio.

Read more about Roslyn :

https://github.com/dotnet/roslyn
https://en.wikipedia.org/wiki/.NET_Compiler_Platform

When to use Roslyn

If your project having Roslyn references and you are going to deploy it on server, you might get unexpected errors on the website as many hosting providers still have not upgraded their servers and hence do not support Roslyn. To resolve this issue, you’ll need to downgrade it or remove the Roslyn compiler from the project template.

Way 1 : Upgrade NuGet packages

Follow the below steps one by one

  • Delete all the bin and obj folders from your project.
  • Clean solution and rebuild your project again.
  • Run below code in the Package Manager Console to re-install/upgrade Nuget packages:

[su_note note_color=”#ffe466″]PM > update-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r[/su_note]

This re-installs all the dependencies and files of the package (like csc.exe)

Deleting the Bin and obj folder from solution explorer and Build the solution again have also worked for many developer.

[su_box title=”Note: ” box_color=”#ffe466″ title_color=”#151111″]If you are using C# 6 or C# 7 features, then you have to keep DotNetCompilerPlatform nuget package in your project. [/su_box]

If you are not interested in using Roslyn, follow Way 2 as given below to delete it from your solution.

Way 2 : Remove NuGet packages

You can run the below commands using NuGet Package Console

[su_note note_color=”#ffe466″]PM> Uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform PM> Uninstall-package Microsoft.Net.Compilers[/su_note]

After executing above command in Package Console, your web.config file should be auto-updated. In case, If it is not, look for the code as given below in your project web.config and delete this piece of code.

If you are getting same bin\roslyn\csc.exe not found! error. You can resolve it by using any one of the above two ways. If you are still getting same error, I would like to request you please write to us in comment box. We’ll be happy to resolve it with you.

Thanks for reading. Happy Coding!

About Ravi Ranjan Kumar 32 Articles
An Indian who Living, Loving & Learning Technology with different tastes and willing to share knowledge and thoughts.

6 Comments

  1. “this is all happening because your build is trying to find because\bin\roslyn\csc.exe the following packages have been added to your project.” – What?

    • Thanks for point out. Now it makes some sense.Please have a look.
      “this is all happening because your project is trying to find \bin\roslyn\csc.exe path inside your project at run time. The following packages have been added to your project.”

Leave a Reply