1
Vote

ModelState.IsValid - throws an exception of type 'System.EntryPointNotFoundException'

description

I found out that if I unit test following code, ModelState.IsValid throws an exception of type 'System.EntryPointNotFoundException' :
 
[TestClass]
public class UnitTest1
{
    ...
    class MyController : Controller
    {
        public void Run()
        {
            var errorInfo = new ErrorInfo[] { new ErrorInfo("p1", "error 1") };
            var rulesException = new RulesException(errorInfo);
            bool isValid = ModelState.IsValid; // this call is ok
            rulesException.AddModelStateErrors(ModelState, string.Empty);
            isValid = ModelState.IsValid; // throws an exception of type 'System.EntryPointNotFoundException'
        }
    }

    [TestMethod]
    public void TestMethod2()
    {
        var myController = new MyController();
        myController.Run();
    }
}
 
With MVC 2 preview 2.
 
Any ideas?

comments

xhafan wrote Nov 26, 2009 at 5:56 PM

I've fixed that by replacing RulesException.AddModelStateErrors() call by new extension method CopyToModelState():

public static class RulesExceptionExtensions
{

    public static void CopyToModelState(this RulesException rulesException, ModelStateDictionary modelState, string prefix)
    {
        foreach (var errorInfo in rulesException.Errors)
        {
            modelState.AddModelError(prefix + "." + errorInfo.PropertyName, errorInfo.ErrorMessage);
        }
    }

}

wrote Feb 14, 2013 at 12:14 AM