有时在生产服务器上我会出现内存异常。它很少发生,在昨天它发生在6月底和8月底。每次我都能看到这个异常在Windows服务之前被记录了7次,托管应用程序就停止了。 该应用程序是预定的石英工作。唯一的事情是这个作业加载(CSScript.Load)并从本地目录编译cs文件并执行它们,但在加载文件之前它尝试从配置设置获取本地文件夹路径并且内存异常。
代码执行:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var result = config.AppSettings.Settings[key].Value;
堆栈跟踪
System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Exception of type 'System.OutOfMemoryException' was thrown. (C:\Program Files\SoftCo\SoftCo R8 Services\SoftCo.R8.Services.exe.Config) ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at System.Xml.NameTable.Grow()
at System.Xml.NameTable.AddEntry(String str, Int32 hashCode)
at System.Xml.NameTable.Add(Char[] key, Int32 start, Int32 len)
at System.Xml.XmlTextReaderImpl.AddAttribute(Int32 endNamePos, Int32 colonPos)
at System.Xml.XmlTextReaderImpl.ParseAttributes()
at System.Xml.XmlTextReaderImpl.ParseElement()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlTextReaderImpl.Skip()
at System.Xml.XmlTextReader.Skip()
at System.Configuration.XmlUtil.StrictSkipToNextElement(ExceptionAction action)
at System.Configuration.BaseConfigurationRecord.ScanSectionsRecursive(XmlUtil xmlUtil, String parentConfigKey, Boolean inLocation, String locationSubPath, OverrideModeSetting overrideMode, Boolean skipInChildApps)
at System.Configuration.BaseConfigurationRecord.ScanSectionsRecursive(XmlUtil xmlUtil, String parentConfigKey, Boolean inLocation, String locationSubPath, OverrideModeSetting overrideMode, Boolean skipInChildApps)
at System.Configuration.BaseConfigurationRecord.ScanSections(XmlUtil xmlUtil)
at System.Configuration.BaseConfigurationRecord.InitConfigFromFile()
--- End of inner exception stack trace ---
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.Configuration..ctor(String locationSubPath, Type typeConfigHost, Object[] hostInitConfigurationParams)
at System.Configuration.ClientConfigurationHost.OpenExeConfiguration(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath)
at System.Configuration.ConfigurationManager.OpenExeConfigurationImpl(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath, Boolean preLoad)