Note that there are some explanatory texts on larger screens.

plurals
  1. POTryUpdateModel throws NullReferenceException in ASP.NET MVC 3 unit test
    primarykey
    data
    text
    <p>Since I upgraded from MVC 2 to MVC 3 RC, using TryUpdateModel causes a NullReferenceException. This problem only occurs when running my action method as part of a unit test. Running it on the actual server works as expected.</p> <p>Here's a stack trace of the exception:</p> <blockquote> <p>System.NullReferenceException: Object reference not set to an instance of an object. at System.Web.Mvc.JsonValueProviderFactory.GetValueProvider(ControllerContext controllerContext) at System.Web.Mvc.ValueProviderFactoryCollection.&lt;>c_<em>DisplayClassc.b</em>_7(ValueProviderFactory factory) at System.Linq.Enumerable.WhereSelectEnumerableIterator<code>2.MoveNext() at System.Linq.Enumerable.WhereSelectEnumerableIterator</code>2.MoveNext() at System.Collections.Generic.List<code>1..ctor(IEnumerable</code>1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at System.Web.Mvc.ValueProviderFactoryCollection.GetValueProvider(ControllerContext controllerContext) at System.Web.Mvc.Controller.TryUpdateModel[TModel](TModel model, String prefix)<br> ... my own code from here on....</p> </blockquote> <p>In case it matters, my controller has the following signature:</p> <pre><code>[AcceptVerbs(HttpVerbs.Post)] public virtual ActionResult Edit(int id, FormCollection collection) { } </code></pre> <p>My guess is that this has to do with the new way DI works in MVC3, but I can't figure out what I'm doing wrong. Perhaps there is something in terms of DI setup that is required in MVC 3, but wasn't required in MVC 2?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload