内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用
我有以下问题:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +567 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +192 System.Reflection.Assembly.Load(String assemblyString) +35 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +123 [ConfigurationErrorsException: Exception of type 'System.OutOfMemoryException' was thrown.] System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +11569328 System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +485 System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +79 System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +337 System.Web.Compilation.BuildManager.CallPreStartInitMethods() +280 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1167 [HttpException (0x80004005): Exception of type 'System.OutOfMemoryException' was thrown.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11702064 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4870277
如何解决?
在调试模式下运行
在开发和调试应用程序时,你通常会将web.config文件中的debug属性设置为true,并将你的DLL编译为调试模式。但是,在将应用程序部署到测试或生产之前,应该在发布模式下编译组件,并将debug属性设置为false。
在调试模式下运行时,ASP.NET在许多级别上工作方式不同。实际上,当你在调试模式下运行时,GC将允许你的对象保持更长的运行时间(直到范围结束),因此在调试模式下运行时总会看到更高的内存使用量。
在调试模式下运行的另一个经常未实现的副作用是,通过webresource.axd和scriptresource.axd处理程序提供的客户端脚本不会被缓存。这意味着每个客户端请求都必须下载任何脚本(如ASP.NET AJAX脚本),而不是利用客户端缓存。这可能导致性能大幅下降。
资料来源: