I have a fairly simple C# WebAPI2 project that runs locally but after publishing to IIS on a remote machine (Windows Server 2012 R2 Standard) the web page displays the follo
The culprit is the Microsoft.Net.Compilers
package, used to support modern C# syntax/features (version 6.0, 7.0) in your project and in Razor views in particular. Depending on its version, the package requires a particular minimum version of the full .NET framework to be installed on a machine in question.
For instance, the 2.2.0 package requires .NET 4.6+. Even though your project is targeting say .NET 4.5.2, you probably have the latest .NET installed on your development machine, and everything goes just fine. The remote deployment machine only has .NET 4.5.2 installed, and when your ASP.NET application tries to compile resource (e.g. views) at run time, you get error -2146232576
.
Your options:
If you absolutely need to use newish C# features in your project - install the latest .NET framework onto the remote machine.
If you are happy with only more or less modern C# features being available - downgrade the Microsoft.Net.Compilers package to a version that only requires a framework you have on your remote machine. For instance, version 1.3.2 only needs .NET 4.5.
If you do not need the said features at all, simply remove Microsoft.Net.Compilers
and Microsoft.CodeDom.Providers.DotNetCompilerPlatform
(Roslyn CodeDom providers) packages from your project.
Target framework was changed, had to install .NET 4.6 on the Windows Server.
The best way I know is install .net framework 4.7 on your PC.