2
votes

I'm trying to use code contracts in an ASP.NET app (MVC 3), something simple like:

public class MyController : Controller
{
    private readonly MyEntities _db;
    public MyController(MyEntities db)
    {
        Contract.Requires<ArgumentNullException>(db != null);
        _db = db;
    }

As in project settings:

  • Runtime Checking: Full
  • Standard Contract Requires

but at runtime, with db equall to null, I don't get an exception. Odd, as the same test in a console does provide the runtime error.

Is there some part of ASP.Net, MVC, or IIS Express that disables the runtime contracts?

1
What are your CC settings? Maybe post a screendump - Henk Holterman
In addititation to the answer below, we use contracts with MVC3 and it works as expected as well. - Andy

1 Answers

1
votes

Not reproducable with MVC2.

I get parameter exceptions just as expected, running with VS and Cassini.