开发者

Are runtime code contracts compatible w/ ASP.Net?

开发者 https://www.devze.com 2023-02-28 05:27 出处:网络
I\'m trying to use code contracts in an ASP.NET app (MVC 3), something simple like: public class MyController : Controller

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

精彩评论

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