MVC4& EF5 System.ArgumentException:ELMAH日志中已添加具有相同键的项

时间:2013-05-15 07:31:48

标签: asp.net-mvc entity-framework elmah.mvc

我收到“System.ArgumentException:已经添加了具有相同键的项目。”在ELMAH日志中。应用程序在dev上运行正常,没有任何异常。我确信实体中的所有字段都有唯一的名称。 的 CODE:

  [HttpPost]
        public ActionResult Create(Candidate candidate)
        {

            if (ModelState.IsValid)
            {


                candidate.CreatedOn=candidate.UpdatedOn = DateTime.Now;

                db.Candidates.Add(candidate);
                db.SaveChanges();



                //save original image & thumbnail
                if (Request.Files.Count > 0)
                {
                    candidate.PhotoPath = PersistImage(string.Concat(candidate.Name.Split(' ')[0], "-", candidate.Id.ToString()));
                    candidate.ResumePath = PersistResume(string.Concat(candidate.Name.Split(' ')[0], "-", candidate.Id.ToString()));
                    db.SaveChanges();
                }
                MembershipUser user = Membership.GetUser(candidate.UserId);

                if (!user.IsApproved)
                {
                    user.IsApproved = true;
                    Membership.UpdateUser(user);
                }
                TempData.Add("Info", UserMessages.Success);
                FormsAuthentication.SetAuthCookie(candidate.UserId, createPersistentCookie: false);
                return RedirectToAction("Listing", "Job");
            }
            TempData.Add("Info", UserMessages.ValidationFailure);
            ViewBag.CategoryId = CacheManager.GetCategorySelectList(Convert.ToString(Convert.ToString(candidate.CategoryId)));
           // ViewBag.SubCategoryId = new SelectList(db.SubCategories, "Id", "Name", candidate.SubCategoryId);
            ViewBag.QualificationId = new SelectList(CacheManager.GetQualifications(), "Id", "Name", candidate.QualificationId);
            ViewBag.CountryId = new SelectList(CacheManager.GetCountries(), "Id", "Name", candidate.CountryId);

            return View(candidate);
        }

堆栈追踪:

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 Ointerns.Controllers.CandidateController.Create(Candidate candidate)
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()
   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.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<>c__DisplayClass2a.<BeginInvokeAction>b__20()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult)

我已检查过以下主题但无效

An item with the same key has already been added

0 个答案:

没有答案