繁体   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