I have a web app, classic ASP.NET running on Windwes Server SBE 2016 with 64 GB Ram and SQL Server 2017 Standard.
The app is built in VS 2022 latest version.
I need to generate a very large XML, for a national-required financial report. The exported XML results in a file about 6-700 MB.
When I generate this in the development environment with 16 GB ram (and VS 2022 running, Sql Server 2019 developer, IIS Express, etc.) it works.
However when running it in production (Windows server 2016 SBS, IIS 10, Sql Server 2017 Standard) I get Out of Memory most of the time when I try to generate this XML.
To succesfully be able to run it I have to stop Sql server and restart, and stop w3w service and restart. After this I can generate the xml, once, maybe twice, but then it gets OutOfMemory error.
The server isn't running any heavy process, SQL server being the most memory-consuming one, and it takes usually 32 GB (in task manager, as shown below)
This is how the memory load looks usually
The code to generate the XML is doing it using standard Xml objects as
var xmlDoc = new XmlDocument();
// Create the root element with the specified namespace
XmlElement rootElement = xmlDoc.CreateElement(nsSAFT, "AuditFile", SAFTNamespace);
// Append the root element to the XmlDocument
xmlDoc.AppendChild(rootElement);
// ....
Please advise how to overcome this problem.
I'm adding some more information, based on the feedback received.
The OutOfMemory exception is thrown while creating the XML object from the data. If I get to the point where the XmlObject is fully created, returning the Xml doc to the client is working ok - the XML is rendered to a local temp file, and then streamed to the client using a memory stream that reads from the file in chunks and writes to output stream.
After the answers I got, I discovered that the appPool had Enable 32 bit app true (probably it was left from a few years ago when we still used some 32 bit dlls in the app, but no more).
I set that to False and the app generated the Xml successfully.
I'll do a few more tests, but I have the feeling that this will solve the issue.
Thanks again for all the answers.
@jdweng, thanks for pointing out to x64 opt, that brought me to check the appPool's 32 bit setting
@dbc, thanks for the info on GC about server / ws environment, I wasn't aware of that, very interesting info