引发了类型为'System.OutOfMemoryException'的异常。

33

我遇到了以下问题

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

我没有改变代码?这个问题是什么意思,因为我看不到关于错误的任何声明。


在这个异常发生之前,你在做什么? - Nisha
哪个事件触发了这个错误。例如,插入、选择等。 - Sasidharan
5个回答

36

当某些进程(例如将大量数据加载到内存流中)并且您的系统内存无法存储如此多的数据时,通常会出现此问题。尝试通过执行以下命令清除临时文件夹:

开始 -> 运行 -> %temp%


尝试检查您的进程并查看在运行空白页面时内存是否增加。检查系统是否有足够的内存来加载页面。似乎它在页面初始化时崩溃了。 - Nisha
5
阅读此文章。它很棒!http://blogs.iis.net/webtopics/archive/2009/05/22/troubleshooting-system-outofmemoryexceptions-in-asp-net.aspx - inon
1
在我的临时文件夹中只有F文件,我认为这个问题不是由于临时文件引起的。 - Brijesh Mavani

17

另一个尝试的方法是:

工具 -> 选项 -> 搜索IIS -> 勾选为网站和项目使用IIS Express的64位版本

使用IIS Express的64位版本用于网站和项目截图


感谢您的指导,它运行得很好。请问您能否提供服务器配置以在生产站点中修复问题? - Selva
@Selva 在生产环境中,它将在 IIS 下运行,因此您需要检查应用程序正在运行的应用程序池。例如:https://dev59.com/JnE85IYBdhLWcg3wYSdk - Dijkgraaf
1
对于那些在Azure应用服务上部署项目的人来说,可以从“配置”选项卡->“常规设置”->“平台”中进行设置,并将其设置为64位。 - Ziad Akiki

14

运行调试模式

在开发和调试应用程序时,通常会将web.config文件中的debug属性设置为true,并在debug模式下编译DLL。但是,在将应用程序部署到测试或生产环境之前,您应该将组件编译为release模式,并将debug属性设置为false。

在使用调试模式运行时,ASP.NET 在许多方面都有所不同。事实上,在调试模式下运行时,垃圾回收器(GC)允许对象保持活动状态更长时间(直到范围结束),因此在调试模式下运行时,内存使用率总是更高的。

另一个经常被忽视的运行调试模式的副作用是,通过webresource.axd和scriptresource.axd处理程序提供服务的客户端脚本将不会被缓存。这意味着每个客户端请求都必须下载任何脚本(例如ASP.NET AJAX脚本),而不能利用客户端缓存。这可能会导致性能大幅降低。

来源:http://blogs.iis.net/webtopics/archive/2009/05/22/troubleshooting-system-outofmemoryexceptions-in-asp-net.aspx


7

我刚刚重启了Visual Studio并执行了IISRESET,问题得到了解决。


6
如果您正在使用IIS Express,请从任务栏通知区中的IIS Express中选择显示所有应用程序,然后选择停止全部。现在重新运行您的应用程序。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接