[英]How to catch a resource assembly not found exception under .net framework 4?
我最近將DotNetNuke 6安裝切換到.net 4框架,並且我開始遇到以下錯誤:
DotNetNuke.Services.Exceptions.PageLoadException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not find file 'Telerik.Web.UI.resources'.
at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)
at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)
at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
at Telerik.Web.LocalizationProvider.EmbeddedResourceLocator.GetString(String resourceKey)
at Telerik.Web.LocalizationStrings.GetString(String key, Boolean throwErrorIfMissing)
at Telerik.Web.LocalizationStrings.GetString(String key)
at Telerik.Web.UI.ComboBoxStrings.get_AllItemsCheckedString() --- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Web.SecurityUtils.MethodInfoInvoke(MethodInfo method, Object target, Object[] args)
at System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember)
at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember)
at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)
at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)
at Telerik.Web.UI.RadComboBox.DescribeComponent(IScriptDescriptor descriptor)
at Telerik.Web.UI.RadDataBoundControl.Telerik.Web.IControl.DescribeComponent(IScriptDescriptor descriptor)
at Telerik.Web.UI.ScriptRegistrar.GetScriptDescriptors(Control control)
at Telerik.Web.UI.RadDataBoundControl.GetScriptDescriptors()
at Telerik.Web.UI.RadDataBoundControl.System.Web.UI.IScriptControl.GetScriptDescriptors()
at System.Web.UI.ScriptControlManager.RegisterScriptDescriptors(IScriptControl scriptControl)
at Telerik.Web.UI.RadDataBoundControl.RegisterScriptDescriptors()
at Telerik.Web.UI.RadDataBoundControl.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl <....snip, rendering call stack>
我不知道為什么會發生此錯誤,因為我無法在另一台服務器甚至同一台服務器上重現它。 由於找不到解決方案,因此我嘗試對其進行修補,因此我查看了本文中建議的解決方法: http : //social.msdn.microsoft.com/Forums/vstudio/en-US/32e458a1-7443- 4309-a054-8839b33dfd4f / framework-40-dll由20個可執行文件無法找到xxxxresourcesdll加載
因此,解決方法是
在HostRuntime.ResolveAssembly中捕獲FileNotFoundException並返回null。 這樣可以防止進程崩潰。
我可以通過HttpModule向應用程序中添加一些代碼,但是我真的看不到如何修補HostRuntime.ResolveAssembly ...知道嗎?
編輯:我一直在框架4的mscorlib程序集中挖掘,我看到一些很奇怪的東西:
從ManifestBasedResourceGroveler到SatelliteAssembly加載的調用如下:
try
{
runtimeAssembly = this._mediator.MainAssembly.InternalGetSatelliteAssembly(satelliteAssemblyName, lookForCulture, this._mediator.SatelliteContractVersion, false, ref stackMark);
}
catch (FileLoadException ex)
{
int hResult = ex._HResult;
Win32Native.MakeHRFromErrorCode(5);
}
catch (BadImageFormatException)
{
}
因此它捕獲了異常,但這是InternalGetSatelliteAssembly
的代碼
if (runtimeAssembly == this)
{
throw new FileNotFoundException(string.Format(culture, Environment.GetResourceString("IO.FileNotFound_FileName"), new object[]
{
assemblyName.Name
}));
}
好的,所以我總是會得到一個不會被捕獲的FileNotFoundException……對我來說這看起來像是一個很奇怪的行為
根據堆棧跟蹤,它看起來像是Telerik版本問題。 您確定所有正確的程序集都已加載嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.