ASP.NET strange compilation error
I don't know what's wrong with my machine, but it's a while that I'm getting the following strange error from ASP.NET (for all my applications).
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 -1073741502.
Show Detailed Compiler Output:
C:\Windows\SysWOW64\inetsrv> "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /t:library /utf8output /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\75855fbd\1e953b27\assembly\dl3\2689d6b5\f0791420_961fcc01\wnvhtmlconvert.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50开发者_如何转开发a3a\System.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Entity\v4.0_4.0.0.0__b77a5c561934e089\System.Web.Entity.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Web\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\75855fbd\1e953b27\assembly\dl3\d08c81cd\4d77c01f_961fcc01\AjaxControlToolkit.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activation\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activation.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.ApplicationServices\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.ApplicationServices.dll" ......AND SO ON.....
Facts:
- Killing worker process fixes the problem temporarily
- I even reinstalled my .NET framework! It didn't work.
- Restarting IIS doesn't help
What can cause this problem?
I removed Roslyn
related packages by NuGet
and it does work now.
Roslyn
related packages:
- Microsoft.CodeDom.Providers.DotNetCompilerPlatform
- Microsoft.Net.Compilers
P.S: My local IIS doesn't have any problem with Roslyn
but as I publish the project on the server (this is why I don't think the server supports Roslyn
), it shows the following error message:
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 -532462766.
Show Detailed Compiler Output:
C:\Windows\SysWOW64\inetsrv>D:\...\wwwroot\bin\roslyn\csc.exe /t:library /utf8output /nostdlib+ /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\08433893\97359c03_e1abd201\System.Web.WebPages.Deployment.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Extensions\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Extensions.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\2574b56e\eed229e7_dfabd201\Autofac.Integration.WebApi.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualStudio.Web.PageInspector.Loader\v4.0_1.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Web.PageInspector.Loader.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\2da0bd13\b2333a9c_e0abd201\System.Net.Http.Formatting.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\99fd000f\fe3c7c0e_e1abd201\System.Web.WebPages.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\695a732a\7a32e84e_e2abd201\WebGrease.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.Activities.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\ca091706\f1f4ae28_78afd201\Core.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\ce3c4f34\2b7b911a_e0abd201\EntityFramework.SqlServer.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\c73494ac\8f453228_78afd201\CommonViewModels.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Web.Infrastructure\v4.0_1.0.0.0__31bf3856ad364e35\Microsoft.Web.Infrastructure.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.WorkflowServices\v4.0_4.0.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\03d13810\0845500f_e1abd201\System.Web.Http.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\5cc83c73\51b7f8fe_e0abd201\System.Web.Http.WebHost.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\290d81d3\fb074b29_78afd201\Data.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activation\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activation.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\7a5d0293\283dbf3a_e0abd201\GridMvc.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\eb50e8c6\1900fa91_e0abd201\System.Web.Razor.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\a7d6ceb3\4c5f9c2c_78afd201\Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Deployment\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Deployment.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.DynamicData\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.DynamicData.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\3bd130ea\7b432ba6_e0abd201\System.Web.Optimization.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\8486430e\674206e7_dfabd201\Autofac.Integration.Mvc.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\c0d9cc06\83811806_e1abd201\System.Web.WebPages.Razor.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\8835020a\58c1c60e_e1abd201\System.Web.Helpers.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\30c33f64\00d8a820_d154d201\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Web\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\6ea00d7f\02323228_78afd201\Extensions.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\f8f1e397\e9660a29_78afd201\Services.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\ff57243f\bb5e8b92_e0abd201\System.Web.Mvc.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Deployment\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Deployment.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activities.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\fd2c5d18\00ae74dd_e7acd201\Autofac.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.ApplicationServices\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.ApplicationServices.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\a44c79bb\74928fbb_e0abd201\EntityFramework.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\227cd18a\6ab66d28_78afd201\Domain.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\assembly\dl3\8cbb60ec\00788858_b3abd201\Newtonsoft.Json.dll" /out:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\App_Code._bgj8eyw.dll" /debug- /optimize+ /warnaserror- /w:4 /nowarn:1659;1699;1701;612;618 /langversion:6 /nowarn:1659;1699;1701 "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\App_Code._bgj8eyw.0.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a47e39f5\cc42bc06\App_Code._bgj8eyw.1.cs"
How to uninstall the
Roslyn
packages.
In the Solution Explorer, by Right-Click on the web project, select Manage NuGet Packages...
.
Go to Installed
tab then search the related Roslyn
packages as mentioned at above.
Use Uninstall
button to delete them.
OK, after days struggling with this issue, I finally fixed it.
- Not by clearing ASP.NET temp
- Not by reinstalling the .NET framework!
Simple!
- I changed the application pool identity from "Local system" to "ApplicationPoolIdentity"
Apparently there was a permission error with my local system that the C# compiler (csc.exe) could not access some resources and source codes.
In order to change your AppPool identity follow steps given here: http://learn.iis.net/page.aspx/624/application-pool-identities/
What worked for me... It seems if you install (or a dependent package installs) Microsoft.CodeDom.Providers.DotNetCompilerPlatform
NuGet package it makes some web.config
transforms that allow you to use C#7.x features in ASP.NET Razor pages. Whilst I found these worked fine on my local machine they didn't work on our server (even when the compiler was in the /bin/ folder).
The solution was to locate the element below and remove completely from 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 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=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
Delete C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\
I got this kind of error too, but the problem was very different explained here. So in my case I got compiler error from temp file that I was using non existing namespace like:
using ImaginaryNamespaces;
I was sure that code "using ImaginaryNamespaces;" dosn't exists in my solution so of course I doubt cache problem. Finally I figured out that the temporary file was some generated source file from configs. My Views/Web.Config had a line:
<add namespace="ImaginaryNamespaces"/>
After removing this it worked. So I recommend to make sure that there is not any data in configs that might be related to the compiler error.
I just ran into this on .NET 4.6.1 and it ultimately had a simple solution - I removed (actually commented out) the section in the web.config and the web forms application came back to life. See what-exactly-does-system-codedom-compilers-do-in-web-config-in-mvc-5 for more info.
It worked for me.
The answers provided are not the solution. The .NET 6# stuff is pretty different from what we used to. A lot has changed, from having to deal with portable libraries to Visual Studio 2015 installing an old compiler (it cost me four hours cracking my head).
The long story short: Stack Overflow question How do I use C# 6 with a Web Site project type?
You need to install the C# .NET compiler (now runs as a service bla bla bla). and you need to run updates on NuGet to get the latest everything (before trying anything else).
The compiler must be installed on the project your solution runs from (so your website or your main project your application starts from (if you have multiple projects)).
Once you install that then sort out your web.config referencing any portable libraries, and delete both the bin
and obj
folder (to avoid works on my computer nightmare), It should just run. But be patient; what happens on your machine may vary as much as the answers above. Most of the answers above hide other problems. It may work for a while, then boom: compiler error. I had a few pages working, then some pages started failing because of some packages that have started using portable libraries.
In IIS Manager, in the advanced settings of the Application Pool, make sure "Process Model → Load User Profile" is set to "True". In my case it worked.
I have crawled through a lot of blog posts including a few Stack Overflow pots, and I already had everything in place what these posts suggested (see below) when I got this error.
- My app pool is running under ApplicationPoolIdentity
- Load user Profile was set to True in Process Model section
- IIS AppPool\DefaultAppPool has full permissions on temp ASP.NET files folder
Finally I found some clues in the below mentioned blog post. It looks like there is heap contention with the same user account. So I changed the app pool identity to LocalSystem, for the app which is failing with this error - and my app started working fine.
See blog post C# compiler or Visual Basic .Net compilers fail with error code -1073741502 when generating assemblies for your ASP.net site.
Note: LocalSystem account will not have much permissions. In my case my application does not need any special permissions. So I was fine. If your application needs special permissions try configuring a custom account.
If you get the error "An error occurred during the compilation of a resource required to service this request. Compiler Error Message: The compiler failed with error code 255."
Try to terminate the processes "VBCSCompiler.exe". VBCSCompiler.exe can also be the problem if your application can not build due to the fact that some packages can not be transferred to the bin folder.
I resolved this by deleting the contents of the bin and obj folders for the project, and the contents of the bin folder on the remote server, then redeploying.
If you are still struggling to solve this issue, even after all options, then try to find application which is running and taking huge memory.
In my case it was an application which was having more than 100 instances running due to some error and that was taking at least 20 MB per application so around 2 GB.
After I killed the few applications and memory was released my site was back online.
If you did deploy this application into your server, it's possible that the *.config files in folder \bin\roslyn were deleted.
Then review if exist the files like:
- csc.exe.config
- csi.exe.config
- vbc.exe.config
- VBCSCompiler.exe.config
These files can be variate depending on your project references.
Cause: I have noticed that when I clean my project or clean one of the dependent projects and then hit refresh a few times on the page showing the site then it causes this error. It seems like it tries to load/run a broken/missing DLL project somehow.
Rename the project’s IIS directory to something different and with new name it loads fine (again providing project is built first OK then run otherwise it causes the same issue)
I got the same error, came out of nowhere. After several hours of trying all the solutions mentioned here and on other forums, what worked for me was simple "Clean Solution" and "Rebuild" in VS2015.
I had to kill multiple instances of MSBuild.exe hanging in process explorer.
Then the website runs OK.
Updating Nuget packages fixed proglem for me.
I had this error message and for me the solution was to install Dot Net Framework 4.6 ,While my project targeted 4.5.2
The version of the Microsoft.Net.Compilers (3.0) used in my project was incompatible with the version of .NET installed on the server.
I downgraded the version to 2.1 and everything work fine now.
I guess it's related to the different versions of .Net framework (guessing .NET Core) installed on the server.
This kind of errors appears "strange" because they are related to the .NET Framework dynamic source code generation and compilation feature, and, in my opinion, the various errors generated are not reported with all the information needed to understand the real root cause. IIS will report only a generic failure like "Configuration Error" or "Compilation Error", the command line of the dynamic compilation (with reference to temporary files created on-the-fly), and an error code.
Since the error is generic, by searching it on Internet (and in answers to this question), you'll find several different solutions that solved the issue for other people, but will not necessarily solve the issue for your specific case.
For the specific error reported in this question "-1073741502", the root cause appears to be a "DLL Initialization Failed" error during the compilation and from the following article it is likely to happen when the system is low on what is called Desktop Heap memory: https://blogs.msdn.microsoft.com/friis/2012/09/19/c-compiler-or-visual-basic-net-compilers-fail-with-error-code-1073741502-when-generating-assemblies-for-your-asp-net-site/ .
The same blog post suggests to change the app pool account to give more "Desktop Heap memory" or to increase it by changing Windows registry. And the solution to change the app pool account is the one accepted for this answer: https://stackoverflow.com/a/6929129/1996150
Since the "dynamic compilation" of ASP.NET pages appears to be not mandatory if all the code is already compiled within Visual Studio, in many cases similar errors can be solved by manually removing the element "<system.codedom>" from web.config file or removing the Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet package (see https://stackoverflow.com/a/49903967/1996150).
精彩评论