2013-06-19 36 views
0

我在IIS 7上有ASP.NET MVC 3应用程序的错误行为。我们在代码中存在堆栈溢出情况,并且导致一般的应用程序池崩溃没有正确的System.StackOveflowException抛出投掷。因此,开始执行有问题的功能之后,w3wp.exe将以本机代码异常停机。关于堆栈溢出(未处理)的IIS崩溃 - Microsoft .NET 4.5 ASP.NET MVC 3

这里的HtmlHelper扩展的代码(现在 - 固定):

public static string Avatar(this UrlHelper helper, string fileName) 
    { 
     return helper.UserAvatar(fileName); 
    } 

public static string UserAvatar(this UrlHelper helper, string fileName) 
    { 
     if (string.IsNullOrEmpty(fileName)) 
      return EmptyPhotoImage(helper); 

     var photoPath = System.Web.Hosting.HostingEnvironment.MapPath(string.Format("~/Content/avatars/{0}", fileName)); 
     if (!File.Exists(photoPath)) 
      return EmptyPhotoImage(helper); 

     return Avatar(helper, fileName); 

    } 

这里是事件日志记录:

Faulting application name: w3wp.exe, version: 7.5.7601.17514, time stamp: 0x4ce7afa2 
Faulting module name: ntdll.dll, version: 6.1.7601.17725, time stamp: 0x4ec4aa8e 
Exception code: 0xc00000fd 
Fault offset: 0x0000000000055d7f 
Faulting process id: 0x1a6c 
Faulting application start time: 0x01ce6c67c7179807 
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe 
Faulting module path: C:\Windows\SYSTEM32\ntdll.dll 
Report Id: 0dd50093-d85b-11e2-9ee7-50e549e13906 

其他一个:

Fault bucket , type 0 
Event Name: APPCRASH 
Response: Not available 
Cab Id: 0 

Problem signature: 
P1: w3wp.exe 
P2: 7.5.7601.17514 
P3: 4ce7afa2 
P4: ntdll.dll 
P5: 6.1.7601.17725 
P6: 4ec4aa8e 
P7: c00000fd 
P8: 0000000000055d7f 
P9: 
P10: 

我的问题:为什么它会导致没有StackOverflowException异常的池崩溃?

回答

1

因为您导致递归无限调用。

头像调用UserAvatar,如果满足某些条件(例如,当磁盘上没有文件时),则调用Avatar。

因此,StackOverflowException使应用程序无法继续运行。这就是为什么你会得到一个本地异常(因为它的CLR是crasching。事件0xc00000fd是一个StacokOverflowException)