0

我收到“System.ArgumentException:已添加具有相同密钥的项目。” 在 ELMAH 日志中。该应用程序在 dev 上运行良好,没有任何例外。我确信实体中的所有字段都有唯一的名称。 代码:

  [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)

我已经检查了下面的线程,但无济于事

已添加具有相同密钥的项目

4

0 回答 0