合同。 VS发出声音,使用合同时一切都停止了......为什么? [英] Contracts. VS emits a sound and everything stops when using Contracts ... Why?

查看:73
本文介绍了合同。 VS发出声音,使用合同时一切都停止了......为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我在.NET 4.5类库中有以下方法:

I have the following method on a NET 4.5 class library:

    public static String GetSalt(Int32 size) {
      Contract.Requires<ArgumentOutOfRangeException>(size > 0, "size must be positive");
      // Rest of code
    }

类库构建没有任何问题。

The class library builds without any problem.

然后我使用它在一个MVC 4项目中,当我调用该方法时,我从Visual Studio中获取声音。

I then use it on a MVC 4 project and when I call that method I ear a sound from Visual Studio.

没有异常,没有错误,没有消息......只是一个声音。一切都停止了。

No exception, no error, no message ... Just a sound. And everything stops.

如果我在我的方法中删除合同一切正常......

If I remove Contract in my method everything works fine ...

我已经花了很长时间试图签订合同工作。

I have been for quite a while trying to make Contracts work.

我知道我做错了什么?

人们在使用这个类库时会遇到问题吗?

And will people have problems when using this class library?

谢谢,

Miguel

推荐答案

嗨Miguel,

Hi Miguel,

是否有可能将错误的参数传递给该方法并且代码合同是否尝试显示失败的断言对话框但由于某种原因 你看不到它? 在运行服务应用程序(例如ASP.NET
网站)时,除非在本地托管服务以进行调试时,否则不应使用断言对话框。

Is it possible that a bad argument is being passed to that method and Code Contracts is trying to show the failed assertion dialog but for some reason you can't see it?  When running a service application, such as an ASP.NET website, you shouldn't use assertion dialogs except when hosting the service locally for debugging purposes.

On 项目属性的代码合同页面,请确保取消选中
断言合同失败。  禁用该选项后,该应用将会相反,如果连接了它,它将进入调试器。

On the Code Contracts page of your project's properties, make sure that you uncheck Assert on Contract Failure.  With that option disabled, the app will crash instead, and it will break into the debugger if one is attached.

- Dave


这篇关于合同。 VS发出声音,使用合同时一切都停止了......为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆