这是一个非常奇怪的情况,所以希望我能很好地解释它。
我正在将 ASP.NET 4 webforms 应用程序部署到运行 IIS6 的 Windows Server 2003 SP2 服务器。
这就是问题所在——当应用程序池回收其工作进程 (w3wp.exe) 时,大约 80% 的时间,我每次尝试访问应用程序中包含 EntityDataSoure 的任何页面时都会收到 ReflectionTypeLoadException 错误尝试查看它。
但是(这是有趣的部分)——另外 20%,它工作得很好。实际上,我已经为这个应用程序池完全关闭了工作进程的回收,只是从 web.config 中添加/删除空格,强制站点重新编译,直到我得到一个“好的”w3wp.exe。
如果不清楚,我的意思是:实际的工作进程对于包含 EntityDataSource 的页面根本不起作用大约有 4/5 次启动,但仍然设法为所有其他页面提供服务美好的。一旦您获得一个工作进程,它设法为带有 EntityDataSource 的页面提供服务,它每次都会工作,直到该进程被回收。
我的问题是,我该如何调试它?它在我的开发机器上运行良好,只要您运行良好的进程,它在服务器上也能正常运行,但是 iisreset 或服务器重新启动或任何杀死工作进程的东西几乎可以保证导致站点无法恢复并且抛出此 ReflectionTypeLoadException。
这是我的 web.config 的编译部分:
<compilation debug="false" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
以下是我掌握的有关此异常的所有信息:
Application information:
Application domain: /LM/W3SVC/1/Root/name-5-129230865053805490
Trust level: Full
Process information:
Process ID: 3300
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE
Exception information:
Exception type: ReflectionTypeLoadException
Exception message: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Thread information:
Thread ID: 6
Thread account name: NT AUTHORITY\NETWORK SERVICE
Is impersonating: False
Stack trace: at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.Assembly.GetTypes()
at System.Data.Metadata.Edm.ObjectItemConventionAssemblyLoader.LoadTypesFromAssembly()
at System.Data.Metadata.Edm.ObjectItemAssemblyLoader.Load()
at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, ObjectItemLoadingSessionData loadingData)
at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, KnownAssembliesSet knownAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage, Object& loaderCookie, Dictionary`2& typesInLoading, List`1& errors)
at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage)
at System.Data.Metadata.Edm.ObjectItemCollection.ExplicitLoadFromAssembly(Assembly assembly, EdmItemCollection edmItemCollection, Action`1 logLoadMessage)
at System.Data.Metadata.Edm.MetadataWorkspace.ExplicitLoadFromAssembly(Assembly assembly, ObjectItemCollection collection, Action`1 logLoadMessage)
at System.Web.UI.WebControls.EntityDataSourceView.ConstructContext()
at System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)
at System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.ListControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()
at System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e)
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
没有对项目中的任何文件进行任何更改,所以我不明白为什么有时我得到一个“好的”w3wp.exe 而有时我得到一个“坏的”w3wp.exe。
最佳答案
检查您是否没有在同一应用程序池中运行针对较低版本 (< 4.0) 构建的另一个 ASP.NET 站点。与 ASP.NET 1.1 和 2.0 一样,ASP.NET 4.0 不能与其他版本共存于同一个工作进程中。
更新
我没有捕捉到报告此异常的部分,因为它不在 View 中:
Exception message: Unable to load one or more of the requested types.<br/>
Retrieve the LoaderExceptions property for more information.
^ ^ ^ look up, the framework is helping us for a change ^ ^ ^
你能在你的代码中围绕这个包裹一个 try/catch block 并转储你发现的异常吗?
类似下面的代码会做:
try
{
//Do your entity data thing in the page...
}
catch(ReflectionTypeLoadException rtle)
{
foreach(Exception ex in rtle.LoaderExceptions)
{
Debug.WriteLine(ex.ToString());
}
}
LoaderExceptions
是 ReflectionTypeLoadException
的成员抛出的异常,包含类加载器抛出的异常数组。
这应该可以帮助您缩小范围,如果没有,请张贴您在其中找到的异常列表。
关于c# - 将 ASP.NET 4 Web 应用程序部署到 IIS6 服务器后,工作进程回收导致其大部分时间停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3206848/