开发者

Are runtime code contracts compatible w/ ASP.Net?

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?


Not reproducable with MVC2.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜