26

Symptoms: ASP.NET Web Forms website on Azure sporadically crashes and all .aspx page requests fail with this error. The problem seems random and only happens once in a great while. The site may run for months with no issues then out of the blue it will stop serving any .aspx pages and gives the error on every .aspx page request. A restart of the website is the only solution (or redeploy, which causes the same thing).

This was a very difficult problem to debug since it was so sporadic and none of the other answers I found helped, they did not address the problem where the site would deploy and run for long periods of time then crash with this error seemingly randomly. In the end I got some help from Microsoft.

Eric Sassaman
  • 1,401
  • 1
  • 18
  • 23

5 Answers5

37

According to Microsoft this is caused by a known bug with the .Net Framework versions 4.7.x triggered by memory pressure in the web server worker process. It is fixed in .Net framework 4.8 (not yet released at this time). My solution was simply to check "allowed precompiled site to be updatable" and check the "Do not merge" option.

Details from Microsoft:

The root cause of the issue is relating to the memory pressure on the worker process (w3wp.exe) address space. In ASP.net, when the .Net Framework detects that we have exceeded a certain memory pressure threshold, it will proceed to try and eject items from the internal caching structures in order to relieve space. Upon such a cache trim, assemblies belonging to your application are removed from the memory cache. This triggers a callback delegate that will try and reflect that changes in memory cache onto the cache of assemblies on disk – and will try and delete the .dll assembly ejected from the in-memory cache. However, the worker process is still keeping a reference to this file (an open handle) and as such, the delete fails. When this occurs, the .Net Framework creates a .delete file next to the assembly to mark it as stale. This will prevent the worker process from loading the file back into memory cache and causes the compilation error you are seeing.

The cause of all of this cache processing is an incorrect insertion into the ASP.net memory cache of dynamic assemblies issued from the pre-compilation process with non-updatable UI. In this process of compilation, the names of the dynamic assemblies cannot be changed, as the .compiled resource files which indicate to the ASP.net Runtime where a compiled resource is located (in what binary) do not change if changes are made to the site – contrary to the pre-compilation with updatable UI, where the markup for pages can be subject to change, and this generates changes to the .compiled files and then to the names of the dynamic assemblies, thus preventing the re-usage of the old names.

For assemblies that have come from the pre-compilation of an ASP.net application with non-updatable UI, the standard was to insert them into the ASP.net memory cache in the worker process with a special attribute that would indicate to the cache manager that these entries cannot be removed. This attribute is missing in the .Net Framework 4.7.x release builds and is the cause of the error. Without it, when the cache is trimmed, the assemblies can be removed, and since they are still in usage, they cannot be deleted from the Temporary ASP.net Files folder (the shadow copy folder). As such, this results in the creation of the .delete files. This was not an issue in builds of the .Net Framework prior to 4.7. The product group has also confirmed that they have resolved this issue in the upcoming .Net Framework 4.8 release.

There are a couple of solutions around this issue:

Remove the 4.7.x .Net Framework and re-install the 4.6.x Framework.

The caching error is only present in builds of the .Net Framework of 4.7 and above, thereby reverting to a 4.6.x version would allow you to continue working without facing the problem. They can remain in the 4.6.x distribution until the .Net Framework 4.8 is released later this year. I do not have a timeline from the product group for this release as of now.

Increase RAM and private bytes recycling limitations. (Does not apply to Azure webapps)

The cache is trimmed in ASP.net when we see that the memory pressure is too great inside the worker process. This memory pressure is evaluated as follows: if you do not have a recycling condition set in the application’s application pool in IIS, ASP.net will consider the threshold to be 60 % of the total RAM available to the machine. When the private bytes of the worker process exceed this threshold, the internal cache will be trimmed, and the assemblies will be ejected, causing the appearance of the .delete files. I advise you work with the customer to increase the RAM memory available to their most impacted servers if possible, and also set a memory recycling based on private bytes on the app pool hosting the impacted application. We can set this recycling limitation to a higher value than the RAM so that we can ensure the threshold is high enough not to be reached by the worker process.

To set the private bytes recycling on the application pool:

  1. Start the IIS Manager console on the impacted servers.
  2. Right click the impacted application pool and chose ‘Recycling’ from the context menu that is displayed.
  3. In the recycling properties window that is displayed, introduce a value for the ‘Private Memory Usage (KB)’ textbox.
  4. The value should be 1.2 * available RAM expressed in KB. This is a temporary workaround, and should be rolled back once the new version of the .Net Framework is released and installed.

Install the .Net Framework 4.8 Preview

You can try to install the preview version of the .Net Framework 4.8 which is available for download online now. However, this is a preview version and you may run into other issues which will not be supported until the Framework is released. You can also opt to install a private fix from Microsoft (reach out to me if you want this nand I will request it), which will change the malfunctioning assemblies from the .Net Framework 4.7.x to allow correct insertion of assemblies into the cache. However, this private fix is not signed, and will hence require us to disable assembly sign checking on the server which may expose the customer to other security risks.

In project precompile options, check "Allowed precompiled site to be updatable" and "Do not merge" options.

The bug only affects non-updatable precompiled binaries, so this avoids the bug, but startup times are obviously greatly affected. For me, this solution was simple and works fine until 4.8 rolls out for Azure web services.

Community
  • 1
  • 1
Eric Sassaman
  • 1,401
  • 1
  • 18
  • 23
  • Thanks for the answer, do you have a link or anything we can refer to regarding this issue? – hrnt Apr 23 '19 at 15:29
  • Sorry, no. This came from an internal bug database at MS that doesn't have public access, according to the support engineer that supplied that info. – Eric Sassaman Apr 28 '19 at 03:50
  • 1
    I had this problem also on 4.6. I want to love it but ASP.NET + Azure is one big MESS. On-Azure-compilation is SUPERslow (+30 seconds for a single page), and the only solution for this actually randomly crashes your whole application. – Dirk Boer Jun 11 '19 at 15:18
  • How can this question only have 4 upvotes. This whole ecosystem feels like a desert. – Dirk Boer Jun 11 '19 at 15:19
  • 1
    @DirkBoer from what MS sent me, the workaround for this bug which was introduced in 4.7.x is to revert back to 4.6.x which supposedly does NOT have this particular bug. So if you are seeing this error in 4.6.x it may be caused by something else. I found quite a few other causes of that error message, it can be caused by lots of other things. Hopefully you can find a solution elsewhere. – Eric Sassaman Jun 12 '19 at 19:50
  • 1
    @hrnt Its in the .Net 4.8 release notes: " Fixed an issue introduced in ASP.NET 4.7, where the unexpected removal of a particular type of cache item can result in an orphaned *.delete file that prevents web applications from running. [750653, System.Web.dll, Bug, Build:3734]" https://github.com/microsoft/dotnet/blob/master/releases/net48/dotnet48-changes.md – Ries Vriend Jun 20 '19 at 20:58
  • 1
    Huge thanks for this. Shame on MS for not making the bug public (or rolling out a 4.7.3 release). This bug has been killing us for months now – SGS Nov 08 '19 at 14:45
  • @DirkBoer I upgraded my Azure App Service (West US) app very recently to 4.8 and it's running great. I changed my publish precompile settings to "merge all outputs" and unchecked "allow ... updatable" and so far so good, so 4.8 is available, but it may take a long time for the bug to re-appear so I can't definitively confirm the fix, but if it ever happens again, I'll post here asap! – Eric Sassaman Dec 29 '19 at 22:50
  • Hi @EricSassaman, thanks for checking back in here! That's great to hear. I don't see the option though yet in my environment - not on my West Europe plans or when I try to make a new US plan. Hopefully soon.. – Dirk Boer Dec 30 '19 at 23:35
  • 2
    I have some very bad news, the bug just crashed my website running on 4.8. It doesn't appear to be fixed! I am disappointed beyond belief. This bug makes pre-compiling completely useless. So now I'm back to no precompiling and unbelievably long startup times for the website. Sigh. – Eric Sassaman Dec 31 '19 at 11:24
  • Hi @EricSassaman, thanks for keeping this up to date - are you running on Azure? According to this: https://feedback.azure.com/forums/169385-web-apps/suggestions/37566262-upgrade-app-service-with-net-4-8 they don't have support for 4.8 in Azure yet... – Dirk Boer Apr 01 '20 at 11:41
  • Well now I'm confused. I have had two West US web app services running since late December '19, targeting 4.8... Both have .net 4.8 set as Target Framework in the Project properties page, web configs have ` and ` and it has been working... – Eric Sassaman Apr 03 '20 at 00:26
  • OK it looks like for sure Azure isn't getting [4.8 support until July-Sept 2020](https://github.com/Azure/app-service-announcements/issues/249). So I can only assume that setting 4.8 in my web.config is ignored? Defaults to 4.7.2 maybe?? Which explains why setting 4.8 didn't fix the pre-compile error! – Eric Sassaman May 23 '20 at 22:34
  • What is the current state of this bug? We are using 4.6.1 and facing this problem. Some comments posted about a year ago states this issue was still existed on december 2019? What is the current situaion of 4.8 now? – Mp0int Feb 24 '21 at 12:06
  • I have not run into this problem since switching to 4.8 some time ago in late 2020. HOWEVER note that MS says this bug was introduced in 4.7 and NOT in versions before then. So this particular bug is probably not your issue. – Eric Sassaman Feb 26 '21 at 07:43
  • Hi @EricSassaman. We are also getting this error on .Net Framework 4.7.2, but does not have option to downgrade to 4.6.2 or perform an easy upgrade to 4.8. I was thinking what is meant by "available RAM" in these sentences: [The value should be 1.2 * available RAM expressed in KB. This is a temporary workaround, and should be rolled back once the new version of the .Net Framework is released and installed.] Are Microsoft referring to available RAM on the server? – Jesper Tejlgaard Nov 03 '22 at 12:16
  • Above that they state "ASP.net will consider the threshold to be 60% of the total RAM available to the machine" so my take on that is whatever memory the worker process has available to it. If you're running in a VM it COULD be whatever memory is available to the VM, not the hardware itself, but I'm just guessing. Beyond that your guess is as good as mine. Try that workaround and see. – Eric Sassaman Nov 04 '22 at 14:02
2

I get the same problem from time to time, on aleatory pages that where working and suddenly stop. Like this Pre-compile

But i know for a fact that the page is pre-complied The "WORKAROUND" for me is very strange.

  1. Go into the Temporary ASP.NET Files folder in the offending server,
  2. Search for 0kb .deleted files
  3. Delete them.

Solution

Eric Sassaman explains, in his answer, why this happens. Will try to upgrade to 4.8 and see if it solves the issue.

*I've been having this issue, and applying my workaround, since 4.2, i think. I find it strange that microsoft states that is was introduced with 4.7. Today i gave another shot at finding the root cause of the problem and found this thread.

Thank you Eric for your efforts, for contacting Microsoft and posting their response.

  • This fix helped us immediately solve a sudden onset of this issue which had us perplexed and our system down. We had just recently migrated to a new server with framework 4.7.2. – royappa Dec 15 '21 at 04:51
1

In case it was working before, and suddenly you get this error message, try setting the 'Enable 32-Bit Applications' to True in the advanced options of the ApplicationPool.

Vincent
  • 2,073
  • 1
  • 17
  • 24
1

Microsoft's gave some advice here... Microsoft article

...to remove just the files in the "root" folder...

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET\root

For us, this didn't work (neither did restarting IIS, our server, enabling 32-bit, etc).

We needed to delete all of folders and files under this folder: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET

Oh, and to check whether you do have .Net Framework 4.7 installed (which is the cause of this issue), you can check the registry here:

enter image description here

My head hurts...

Mike Gledhill
  • 27,846
  • 7
  • 149
  • 159
0

I just wanted to post here, because it might be relevant to other people. I had a large legacy project in ASP.NET Framework 4.7/4.8 running in Azure.

I had a lot of problems with the "live" compilation of pages on Azure. With a lot I mean really a lot. Sometimes I hit a page that wasn't precompiled and Azure seemed to exhaust all resources just on the compilation, bringing the whole application down. After a restart it took 8 (!!) minutes before it could handle the first hit. Local it was only like 30 seconds.

During Corona I finally had time to move to .NET Core - and all these problems instantly went away.

Despite that Microsoft says they will continue supporting .NET Framework for a long time, it is clear to me that Microsoft doesn't have any passion for that project anymore. The issues I had in combination with Azure were ridiculous.

I strongly recommend to migrate as soon as possible. Even for a large project it was less painful than I imagined beforehand.

Dirk Boer
  • 8,522
  • 13
  • 63
  • 111