How to increase allocated memory ? {The function evaluation was disabled because of an out of memory exception.}

Bill picture Bill · Oct 30, 2013 · Viewed 12.6k times · Source

My goal is to load 1.48 million items from XML files into a in memory generic collections dictionary using C# ASP.NET MVC along with ability to render filter lists to views. Right now it works with about 1/2 million items in my dictionary as a single user in VS debug mode. Any more I get out of memory errors - right now I get: myDictionary.Count results in System.TypeInitializationException - 'The function evaluation was disabled because of an out of memory exception.'

In the past it has also been mscorlib.dll during the load from XML to Dict that has complained about out of memory.

I have plenty of system memory left, how can I give more to this MVC Web application? BTW, I tried XML to a Perl Dictionary and it works just fine with 1.5 million objects - no problem. I don't wish to write my app in Perl. If Perl can do it, C# has to be able to do it - I just have not been able to find a solution searching the web yet.

Example Code:

Dictionary<string, msg> masterDictionary = new Dictionary<string, mgs>();

foreach (string file in filePath)
{
    XDocument xdoc = XDocument.Load(file);
    Dictionary<string, msg> fileDictionary = xdoc
        .Descendants("msg")
        .ToDictionary(m => m.Element("msgId").Value,
                      m => new msg
                           {
                               msgId = m.Element("msgId").Value,
                               msgType = m.Element("msgType").Value,
                               name = m.Element("name").Value
                           });

    //now insert your new values into the master
    foreach(var newValue in fileDictionary)
        masterDictionary.Add(newValue.Key, newValue.Value);
}

Answer

Bill picture Bill · Nov 1, 2013

This DID FIX the problem. I'm still limited to 2 GB of memory from within VS 2013 in debug mode. However, when deploying to IIS7.5, 2008 R2 Server, and App. Pool of dot net 4.0x, I can use a lot more memory for my website. It took the following setting in my web.config. I now need to bump my physical from 8 to 16 GBs; But, that is a different story. Solution:

<gcAllowVeryLargeObjects enabled="true" />

https://msdn.microsoft.com/en-us/library/hh285054(v=vs.110).aspx