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).
Compilat
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:
These files can be variate depending on your project references.
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>
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 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.
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 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.
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.