我有一个ASP.NET MVC应用程序,它创建了一个庞大的字典。为了使其发挥作用,我在gcAllowVeryLargeObjects
部分下的web.config
中启用了<configuration>
:
<runtime>
<gcAllowVeryLargeObjects enabled="true" />
</runtime>
这适用于我的本地环境,但是当它在另一个不受我控制的环境中部署时,会得到System.OutOfMemoryException: Array dimension exceeds supported range
,这与添加该配置之前的错误相同。
我需要什么
如果gcAllowVeryLargeObjects
正确读取了web.config
,我想查看运行时。
为什么我需要它
如果启用gcAllowVeryLargeObjects
模式,我想创建应用程序日志,以验证它是否在其他环境中工作。
我认为他们的IIS服务器上的某些配置可能会覆盖或强制忽略应用程序的web.config中的设置。
答案 0 :(得分:1)
3年后仍然没有答案,我也有同样的问题。花了我两天的时间,终于我开始工作了:
Console.WriteLine("Is64BitProcess :" + Environment.Is64BitProcess); // this works on 64 bit processes only
// make sure that the flag is set, for using objects > 2GB:
Configuration configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSection oRuntimeSection = configFile.GetSection("runtime");
string str = oRuntimeSection.SectionInformation.GetRawXml();
if (str == null)
{
oRuntimeSection.SectionInformation.SetRawXml("<runtime><gcAllowVeryLargeObjects enabled = \"true\" /></runtime>");
configFile.Save();
}