断言不变量的System.ExecutionEngineException [英] System.ExecutionEngineException on asserting broken invariant
问题描述
我在Contract.Invariant()中检查了System.ExecutionEngineException,当不满足不变量时。
I got System.ExecutionEngineException in Contract.Invariant() check when invariant is not satisfied.
推荐答案
是的,这是一条已知的错误信息。当.NET 4.0使用FailFast时,断言断言的情况就是如此,结果消息不是很有用。它应该只是默默地退出,但它不会。
Right, this is a known bad message. When .NET 4.0 uses FailFast as is the case when an assertion is aborted, the resulting message is not very helpful. It should just silently exit, but it doesn't.
你可以取消选中"断言合同失败"。在UI中,这将导致抛出异常而不是断言。
You can either uncheck the "assert on contract failure" in the UI, which will cause an exception to be thrown instead of an assert.
或者,您可以为此连接自己的失败方法(请参阅文档第7.1-7.7节)。
Alternatively, you can wire up your own failure methods (see the documentation Section 7.1-7.7) for this.
这篇关于断言不变量的System.ExecutionEngineException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!