我最近切換的DotNetNuke的6安裝到.NET 4框架,我已經開始收到以下錯誤:如何捕獲.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-loaded-by-a-20-executable-cannot-find-xxxxresourcesdll
因此,解決辦法是
catch the FileNotFoundException in HostRuntime.ResolveAssembly and return null. This should prevent the process from crashing.
我可以添加一些代碼通過HttpModule到應用程序,但我真的不明白我應該如何修補HostRuntime.ResolveAssembly ...任何想法?
編輯:我一直在mscorlib程序組件陷的框架4,我看到的東西很奇怪:
從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,不會被捕獲......看起來像一個非常奇怪的行爲
我很確定,我添加了融合日誌的視圖,沒有看到任何奇怪的版本號。有沒有一種方法可以確保加載的版本是正確的? – samy
我再次檢查了我們的融合日誌,我確信所有版本都與框架4相匹配,並且版本號相匹配 – samy