Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS Compilation Error -2146232576 AspNetInitializationExceptionModule

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 following (after setting customErrors to "Off"):

Server Error in '/' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: The compiler failed with error code -2146232576.

If I grab the detailed compiler output and run it on the IIS server, I get a smartscreen error message saying:

This app can't run on your PC. To find a version for your PC, check with the software publisher.

I'm guessing it's something to do with the compiler version but nothing has changed since it last published.

Any ideas?

like image 900
feganmeister Avatar asked May 10 '17 12:05

feganmeister


People also ask

What is the error code for aspnetinitializationexceptionmodule?

IIS Compilation Error -2146232576 AspNetInitializationExceptionModule Ask Question Asked4 years, 7 months ago Active1 year, 1 month ago Viewed23k times 28 8

How to troubleshoot Azure App Service and IIs?

Collect the following information: Azure App Service: See Troubleshoot ASP.NET Core on Azure App Service and IIS. Select Start on the Windows menu, type Event Viewer, and press Enter. After the Event Viewer opens, expand Windows Logs > Application in the sidebar. Azure App Service: See Troubleshoot ASP.NET Core on Azure App Service and IIS.

How do I deploy a 32-bit application in IIS?

For an x86 framework-dependent deployment ( <PlatformTarget>x86</PlatformTarget> ), enable the IIS app pool for 32-bit apps. In IIS Manager, open the app pool's Advanced Settings and set Enable 32-Bit Applications to True. Browser: HTTP Error 502.5 - Process Failure

What is the exception to the IIS 7 core web engine?

OS Exception: The IIS 7.0 CoreWebEngine and W3SVC features must be installed to use the ASP.NET Core Module. Confirm that the proper role and features are enabled. See IIS Configuration. Browser: 403 Forbidden - Access is denied --OR-- 403.14 Forbidden - The Web server is configured to not list the contents of this directory.


4 Answers

I faced with this problem after upgrade some NuGets and solved with below steps.

Step 1: Remove these NuGet packages from NuGet Package Console

PM> Uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
PM> Uninstall-package Microsoft.Net.Compilers

Step 2: Add these system.codedom lines before closing </system.data> tag in Web.config

    <system.codedom>
        <compilers>
            <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"></compiler>
            <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"></compiler>
        </compilers>
    </system.codedom>

PS: After a while, we removed <system.codedom> completely, for fixed other errors.

like image 95
Amir Astaneh Avatar answered Oct 16 '22 10:10

Amir Astaneh


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:

  1. If you absolutely need to use newish C# features in your project - install the latest .NET framework onto the remote machine.

  2. 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.

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

like image 32
Roman Pletnev Avatar answered Oct 16 '22 10:10

Roman Pletnev


Target framework was changed, had to install .NET 4.6 on the Windows Server.

like image 11
feganmeister Avatar answered Oct 16 '22 08:10

feganmeister


for me helped just remove NuGet packages above:

Microsoft.CodeDom.Providers.DotNetCompilerPlatform

Microsoft.Net.Compilers

Recompile and then add them back.

like image 2
Bladeus Avatar answered Oct 16 '22 09:10

Bladeus