在VS2010 Beta1中使用CodeContract的GroupBy后置条件中出现意外的BadImageFormatException [英] Unexpected BadImageFormatException in a GroupBy poscondition using CodeContract in VS2010 Beta1
问题描述
尝试使用以下合约后置条件中的第二个运行自定义GroupBy会产生意外的错误图像格式错误 static class ContractedQueryMethods { public static IEnumerable < IGrouping < K,T>> ; GroupBy< T,K>(此 IEnumerable < T> source, &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Func < T,K>选择器){ //此后置条件在运行时正确验证 合同 .Ensures(合同 .Result< IEnumerable < IGrouping < K,T>>>()。 选择(x => x.Count())。Sum()== source.Count(), "所有组的总项目数等于源中的项目总数");
< p class ="MsoNormal"style ="LINE-HEIGHT:normal;保证金:0英寸0英寸0英寸mso-layout-grid-align:none"> //以下后置条件在注入代码时会产生意外错误!
合同.Ensures(合同 .ForAll< T>(
source,
(x => 合同 .Result< IEnumerable < IGrouping < K,T>> >()。任何(y => y.Contains(x)))),
;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; "来自源的每个项目属于某个组");
&NBSP; // ...
return Enumerable .GroupBy(source,selector);
< span style ="FONT-FAMILY:Consolas; FONT-SIZE:9pt; mso-bidi-font-family:Consolas"> }
// ...
}
消息:
BadImageFormatException未处理
试图加载格式不正确的程序(Exceptipn from HRESULT:0x80070008
我无法重现它(使用Beta 2),但我不确定我是否有完全的复制品。你能否发给我(或发布)一个显示问题的完整程序?在重写代码执行时你会看到错误,对吧?所以请同时包含一个Main(),它使用导致错误的值来调用方法。
谢谢! (抱歉错误......)
The attempt to run a custom GroupBy with the second of the following contract poscondition produces an unexpected bad image format error static class ContractedQueryMethods { public static IEnumerable<IGrouping<K, T>> GroupBy<T, K>(this IEnumerable<T> source, Func<T, K> selector) { //This poscondition is correctly verified in runtime Contract.Ensures(Contract.Result<IEnumerable<IGrouping<K, T>>>(). Select(x => x.Count()).Sum() == source.Count(), "The total items of all groups is equal to the total items in the source"); //The following poscondition produces an unexpected error during injection of the code! Contract.Ensures(Contract.ForAll<T>( source, (x => Contract.Result<IEnumerable<IGrouping<K, T>>>().Any(y => y.Contains(x)))), "Each item from the source belongs to some group"); //... return Enumerable.GroupBy(source, selector); } //... } Message: BadImageFormatException was unhandled An attempt was made to load a program with an incorrect format (Exceptipn from HRESULT: 0x80070008
I was unable to reproduce it (using Beta 2), but I'm not sure I have the exact repro. Can you please send me (or post) a full program that shows the problem? You're seeing the error when the rewritten code is executed, right? So please also include a Main() that calls the method with the values that cause the error to appear.
Thanks! (And sorry for the error...)
这篇关于在VS2010 Beta1中使用CodeContract的GroupBy后置条件中出现意外的BadImageFormatException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!