簡體   English   中英

復制本地!= true System.Web.MVC-Asp.net MVC 2控制器中的字典錯誤操作前

[英]Copy Local != true System.Web.MVC - Asp.net MVC 2 Dictionary Error in Controller Before Action

服務器負載(每秒50到100個請求)幾個小時並且緩存接近其內存限制后,在ASP.NET MVC(mvc dll版本2.0.0.0)項目中出現一個奇怪的錯誤。 如果我正確讀取錯誤日志(我們使用elmah),則MVC動作參數解析器在進入我的控制器動作之前會失敗。

從錯誤報告(如下)中,似乎涉及到填充動作參數的模型綁定程序。 我檢查了url和查詢字符串,它們在我的所有測試中都能正常工作,沒有什么奇怪的地方可以將它們與其他有效的請求區分開來。 所有參數都存在並且包含有效值。

我正在尋找字典調用,其中一個候選人是我在控制器級別(而不是操作級別)應用的篩選器。 但是,我沒有在錯誤報告中看到該過濾器。

這是MVC 2錯誤嗎? 如果不是MVC錯誤,您將如何進一步調查?

**Code - renamed & simplified but parameters are the same types**
[OutputCache(Duration = 1000000, VaryByParam = "*", Location=OutputCacheLocation.Any)]
public class MyController : Controller
{
   public ActionResult MyAction(Int32 one, Int32 two, Int32 three,string a, string b, string b)
    {
         var modelData= FetchModelData(one,two,three,a,b,c);//load model data
         return View(modelData);
    }

}

        **Error**        
System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at System.Web.Mvc.TypeDescriptorHelper._AssociatedMetadataTypeTypeDescriptor.TypeDescriptorCache.GetAssociatedMetadataType(Type type)
at System.Web.Mvc.TypeDescriptorHelper._AssociatedMetadataTypeTypeDescriptor..ctor(ICustomTypeDescriptor parent, Type type)
at System.Web.Mvc.TypeDescriptorHelper._AssociatedMetadataTypeTypeDescriptionProvider.GetTypeDescriptor(Type objectType, Object instance)
at System.Web.Mvc.TypeDescriptorHelper.<GetTypeDescriptorFactory>b__0(Type type)
at System.Web.Mvc.ModelBinders.GetBinderFromAttributes(Type type, Func`1 errorMessageAccessor)
at System.Web.Mvc.ModelBinderDictionary.GetBinder(Type modelType, IModelBinder fallbackBinder)
at System.Web.Mvc.ControllerActionInvoker.GetModelBinder(ParameterDescriptor parameterDescriptor)
at System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor)
at System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
at System.Web.Mvc.Controller.ExecuteCore()
at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__4()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

- - - - - - - - - - - - - - - - -編輯 - - - - - - - - --------------

問題是RC中的MVC線程錯誤,后來在RTM中修復。
問題是我已經在項目中使用MVC RTM並設置copy local = true!

為什么不能為對System.Web.MVC的引用設置“ Copy Local = true”?

這是答案

首先,我需要向自己證明在服務器上運行的MVC版本錯誤,因此我 本文中使用了本文代碼來測試MVC dll版本並得到了我預期的錯誤:

加載了不匹配或過時的ASP.NET MVC和ASP.NET MVC期貨版本。

ASP.NET MVC的加載版本為:ASP.NET MVC 2 RC 1(2.0.41211.0)ASP.NET MVC期貨的加載版本為:ASP.NET MVC 2 RTM期貨(2.0.50217.0)下載ASP.NET MVC 2 RC 1來自http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=37423#DownloadId=97581.aspx?ReleaseId=37423#DownloadId=97581的期貨。

為什么會這樣?

這是一個SO問題, 建議VS和服務器靜默忽略我的命令 在本地,在將MVC 2 RC從GAC升級到RTM時遇到了一些麻煩。 因此,在我的Visual Studio項目中,我確保為System.Web.MVC設置“本地復制” = true,這使我不必擔心各種服務器上System.Web.MVC的不同版本。

我該如何解決?

顯然,GAC中具有MVC RC的每台服務器都將默默地忽略system.web.mvc的“復制本地”指令,這是在每台服務器上升級到RTM的唯一解決方案。

我發現此鏈接顯示了相同的異常和堆棧跟蹤。 這表明這是RC中的錯誤,但已在RTM中修復。 您是否仍然可以使用該程序集的預發行版本?

我擁有的System.Web.Mvc.dll的文件版本為2.0.50217.0(程序集版本為2.0.0.0)。

我不是ASP.NET MVC 2專家,所以這就是我所能提供的(抱歉)。 如果這不能幫助您解決錯誤,那么我建議您為其提供一份代表賞金。

祝好運!

編輯

將此鏈接添加到有關System.Web.Mvc.dll版本的SO問題: 升級到vs2010后,如何確保我的MVC項目在正確的版本上運行?

從該問題的評論中:

檢查版本號。 RC 2是2.0.50129.0。 發行是50217

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM