CCDoc failed with uncaught exception (at RewriteContractInNewContext)
-
9 februarie 2012 04:05
Hi,
CCDoc crashed in a Silverlight 4 project and a Windows Phone 7 project that both contain mostly linked files from a .NET 4.0 project, but it isn't crashing on the .NET 4.0 project. I don't have a small repro yet, and I'm not sure if I can get one. Is there any way to identify which class is related to the error?
Silverlight:
The command ""C:\Program Files (x86)\Microsoft\Contracts\Bin\ccdocgen" "@obj\Release\Rxx-Silverlightccdocgen.rsp"" exited with code 1.
CCDoc failed with uncaught exception: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Stack trace: at Microsoft.Cci.MutableContracts.ContractHelper.RewriteContractInNewContext.RewriteReference(IParameterDefinition parameterDefinition) at Microsoft.Cci.MutableCodeModel.CodeRewriter.RewriteChildren(BoundExpression boundExpression) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Rewrite(IBoundExpression boundExpression) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Dispatcher.Visit(IBoundExpression boundExpression) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Rewrite(IExpression expression) at Microsoft.Cci.MutableCodeModel.CodeRewriter.RewriteChildren(BinaryOperation binaryOperation) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Rewrite(IEquality equality) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Dispatcher.Visit(IEquality equality) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Rewrite(IExpression expression) at Microsoft.Cci.MutableCodeModel.CodeRewriter.RewriteChildren(UnaryOperation unaryOperation) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Rewrite(ILogicalNot logicalNot) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Dispatcher.Visit(ILogicalNot logicalNot) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Rewrite(IExpression expression) at Microsoft.Cci.MutableCodeModel.Contracts.CodeAndContractRewriter.RewriteChildren(ContractElement contractElement) at Microsoft.Cci.MutableCodeModel.Contracts.CodeAndContractRewriter.RewriteChildren(Precondition precondition) at Microsoft.Cci.MutableCodeModel.Contracts.CodeAndContractRewriter.Rewrite(IPrecondition precondition) at Microsoft.Cci.MutableCodeModel.Contracts.CodeAndContractRewriter.Rewrite(List`1 preconditions) at Microsoft.Cci.MutableCodeModel.Contracts.CodeAndContractRewriter.RewriteChildren(MethodContract methodContract) at Microsoft.Cci.MutableCodeModel.Contracts.CodeAndContractRewriter.Rewrite(IMethodContract methodContract) at Microsoft.Cci.Contracts.CodeContractsContractExtractor.GetMethodContractFor(Object method) at CCDoc.CCDocContractHelper.TryGetMethodContract(CodeContractAwareHostEnvironment host, IMethodReference method, IMethodContract& methodContract, DocTracker docTracker) at CCDoc.ContractVisitor.ContractPackager.PackageMethodContracts(IMethodDefinition method, Boolean isPure) at CCDoc.ContractVisitor.Visit(IMethodDefinition methodDefinition) at Microsoft.Cci.MetadataTraverser.Traverse(IMethodDefinition method) at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 methods) at Microsoft.Cci.MetadataTraverser.TraverseChildren(ITypeDefinition typeDefinition) at Microsoft.Cci.MetadataTraverser.Traverse(INamespaceTypeDefinition namespaceTypeDefinition) at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 namespaceMembers) at Microsoft.Cci.MetadataTraverser.Traverse(INestedUnitNamespace nestedUnitNamespace) at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 namespaceMembers) at Microsoft.Cci.MetadataTraverser.Traverse(INestedUnitNamespace nestedUnitNamespace) at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 namespaceMembers) at Microsoft.Cci.MetadataTraverser.Traverse(IRootUnitNamespace rootUnitNamespace) at Microsoft.Cci.MetadataTraverser.Traverse(IAssembly assembly) at CCDoc.CCDoc.GetContracts(Options options, DocTracker docTracker) at CCDoc.CCDoc.RealMain(String[] args) at CCDoc.CCDoc.Main(String[] args)Windows Phone:
The command ""C:\Program Files (x86)\Microsoft\Contracts\Bin\ccdocgen" "@obj\Release\Rxx-Phoneccdocgen.rsp"" exited with code 1.
CCDoc failed with uncaught exception: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Stack trace: at Microsoft.Cci.MutableContracts.ContractHelper.RewriteContractInNewContext.RewriteReference(IParameterDefinition parameterDefinition) at Microsoft.Cci.MutableCodeModel.CodeRewriter.RewriteChildren(BoundExpression boundExpression) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Rewrite(IBoundExpression boundExpression) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Dispatcher.Visit(IBoundExpression boundExpression) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Rewrite(IExpression expression) at Microsoft.Cci.MutableCodeModel.CodeRewriter.RewriteChildren(BinaryOperation binaryOperation) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Rewrite(IEquality equality) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Dispatcher.Visit(IEquality equality) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Rewrite(IExpression expression) at Microsoft.Cci.MutableCodeModel.CodeRewriter.RewriteChildren(UnaryOperation unaryOperation) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Rewrite(ILogicalNot logicalNot) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Dispatcher.Visit(ILogicalNot logicalNot) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Rewrite(IExpression expression) at Microsoft.Cci.MutableCodeModel.Contracts.CodeAndContractRewriter.RewriteChildren(ContractElement contractElement) at Microsoft.Cci.MutableCodeModel.Contracts.CodeAndContractRewriter.RewriteChildren(Precondition precondition) at Microsoft.Cci.MutableCodeModel.Contracts.CodeAndContractRewriter.Rewrite(IPrecondition precondition) at Microsoft.Cci.MutableCodeModel.Contracts.CodeAndContractRewriter.Rewrite(List`1 preconditions) at Microsoft.Cci.MutableCodeModel.Contracts.CodeAndContractRewriter.RewriteChildren(MethodContract methodContract) at Microsoft.Cci.MutableCodeModel.Contracts.CodeAndContractRewriter.Rewrite(IMethodContract methodContract) at Microsoft.Cci.Contracts.CodeContractsContractExtractor.GetMethodContractFor(Object method) at CCDoc.CCDocContractHelper.TryGetMethodContract(CodeContractAwareHostEnvironment host, IMethodReference method, IMethodContract& methodContract, DocTracker docTracker) at CCDoc.ContractVisitor.ContractPackager.PackageMethodContracts(IMethodDefinition method, Boolean isPure) at CCDoc.ContractVisitor.Visit(IMethodDefinition methodDefinition) at Microsoft.Cci.MetadataTraverser.Traverse(IMethodDefinition method) at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 methods) at Microsoft.Cci.MetadataTraverser.TraverseChildren(ITypeDefinition typeDefinition) at Microsoft.Cci.MetadataTraverser.Traverse(INamespaceTypeDefinition namespaceTypeDefinition) at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 namespaceMembers) at Microsoft.Cci.MetadataTraverser.Traverse(INestedUnitNamespace nestedUnitNamespace) at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 namespaceMembers) at Microsoft.Cci.MetadataTraverser.Traverse(INestedUnitNamespace nestedUnitNamespace) at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 namespaceMembers) at Microsoft.Cci.MetadataTraverser.Traverse(IRootUnitNamespace rootUnitNamespace) at Microsoft.Cci.MetadataTraverser.Traverse(IAssembly assembly) at CCDoc.CCDoc.GetContracts(Options options, DocTracker docTracker) at CCDoc.CCDoc.RealMain(String[] args) at CCDoc.CCDoc.Main(String[] args)Thanks,
Davehttp://davesexton.com/blog
Toate mesajele
-
11 februarie 2012 16:53
Hi,
Here's the repro.
Note that before I was able to reduce it this much, I had actually got it to a point where it wasn't failing but it was producing incorrect documentation; i.e., it succeeded but produced an XML file containing the wrong contract elements. I don't know how that's possible though given the nature of the failure and the document that was produced when it succeeded. The problem appears to be that CCDoc cannot determine the correct target method overload for Accept from within the contract class. When it succeeded it had applied the Accept(ICollection) method as the source for all of the overloads in the contract class, resulting in an XML file where each of the elements that represented an overload of Accept all contained a single contract element: <requires>collection != null</requires>. Clearly this contract is incorrect for two of the overloads, which should have had <requires>add != null</requires>, etc. What's strange is that using WinDbg I was able to identify that the failure case is caused when the tool attempts to pass in an index of 1 that represents Func<T, TResult> for the remove parameter, into a list of parameters for the Accept(ICollection<T>) overload, which of course only has a single parameter named "collection" (index = 0).
using System; using System.Collections.Generic; using System.Diagnostics.Contracts; namespace Test { [ContractClass(typeof(CollectionModificationContract<>))] public abstract partial class CollectionModification<T> { /// <summary> /// 1 /// </summary> /// <param name="collection">Collection.</param> public abstract void Accept(ICollection<T> collection); /// <summary> /// 2 /// </summary> /// <param name="add">Delegate.</param> /// <param name="remove">Delegate.</param> /// <param name="clear">Delegate.</param> public abstract void Accept(Action<T> add, Action<T> remove, Action clear); /// <summary> /// 3 /// </summary> /// <typeparam name="TResult">Type.</typeparam> /// <param name="add">Delegate.</param> /// <param name="remove">Delegate.</param> /// <param name="clear">Delegate.</param> /// <returns>Result.</returns> public abstract TResult Accept<TResult>(Func<T, TResult> add, Func<T, TResult> remove, Func<TResult> clear); } [ContractClassFor(typeof(CollectionModification<>))] internal abstract class CollectionModificationContract<T> : CollectionModification<T> { public override void Accept(ICollection<T> collection) { Contract.Requires(collection != null); } public override void Accept(Action<T> add, Action<T> remove, Action clear) { Contract.Requires(add != null); Contract.Requires(remove != null); Contract.Requires(clear != null); } public override TResult Accept<TResult>(Func<T, TResult> add, Func<T, TResult> remove, Func<TResult> clear) { Contract.Requires(add != null); Contract.Requires(remove != null); Contract.Requires(clear != null); return default(TResult); } } }Thanks,
Davehttp://davesexton.com/blog
-
11 februarie 2012 16:55
By the way, it's also failing in the project that targets .NET 4.0. I don't know why it didn't fail the first time, but it fails consistently now. (Perhaps it didn't even run CCDoc, because the build failed for another reason.)
- Dave
http://davesexton.com/blog
-
4 martie 2012 15:04
I have a similar failure with completely different source. This is with the latest CodeContracts, a 4.0 project, some C++, some CUDA, and a lot of other stuff. There are no Interface contracts in the source code I am working with.
------ Rebuild All started: Project: Stress.Logging.Common, Configuration: Debug Any CPU ------ elapsed time: 124.8002ms EnsureContractReferenceAssemblies: C:\Projects\Stress\Stress.Framework.Common\bin\Debug\Stress.Framework.Common.dll;C:\Projects\Stress\Stress.Framework.Interfaces\bin\Debug\Stress.Framework.Interfaces.dll elapsed time: 3010.8053ms Stress.Logging.Common -> C:\Projects\Stress\Stress.Logging.Common\bin\Debug\Stress.Logging.Common.dll Running Code Analysis... Code Analysis Complete -- 0 error(s), 0 warning(s) CCDoc failed with uncaught exception: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Stack trace: at System.Collections.Generic.List`1.get_Item(Int32 index) at Microsoft.Cci.MutableContracts.ContractExtractor.ExtractClump(List`1 blockList, Int32 startBlockIndex, Int32 startStmtIndex, Int32 endBlockIndex, Int32 endStmtIndex) at Microsoft.Cci.MutableContracts.ContractExtractor.RewriteChildren(BlockStatement blockStatement) at Microsoft.Cci.MutableCodeModel.CodeRewriter.Rewrite(IBlockStatement block) at Microsoft.Cci.MutableContracts.ContractExtractor.SplitMethodBodyIntoContractAndCode(IBlockStatement blockStatement) at Microsoft.Cci.MutableContracts.ContractExtractor.SplitMethodBodyIntoContractAndCode(IContractAwareHost host, ISourceMethodBody sourceMethodBody, PdbReader pdbReader) at Microsoft.Cci.Contracts.LazyContractExtractor.GetMethodContractFor(Object method) at Microsoft.Cci.Contracts.CodeContractsContractExtractor.GetMethodContractFor(Object method) at CCDoc.CCDocContractHelper.TryGetMethodContract(CodeContractAwareHostEnvironment host, IMethodReference method, IMethodContract& methodContract, DocTracker docTracker) at CCDoc.ContractVisitor.ContractPackager.PackageMethodContracts(IMethodDefinition method, Boolean isPure) at CCDoc.ContractVisitor.Visit(IMethodDefinition methodDefinition) at Microsoft.Cci.MetadataTraverser.Traverse(IMethodDefinition method) at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 methods) at Microsoft.Cci.MetadataTraverser.TraverseChildren(ITypeDefinition typeDefinition) at Microsoft.Cci.MetadataTraverser.Traverse(INamespaceTypeDefinition namespaceTypeDefinition) at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 namespaceMembers) at Microsoft.Cci.MetadataTraverser.Traverse(INestedUnitNamespace nestedUnitNamespace) at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 namespaceMembers) at Microsoft.Cci.MetadataTraverser.Traverse(INestedUnitNamespace nestedUnitNamespace) at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 namespaceMembers) at Microsoft.Cci.MetadataTraverser.Traverse(INestedUnitNamespace nestedUnitNamespace) at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 namespaceMembers) at Microsoft.Cci.MetadataTraverser.Traverse(IRootUnitNamespace rootUnitNamespace) at Microsoft.Cci.MetadataTraverser.Traverse(IAssembly assembly) at CCDoc.CCDoc.GetContracts(Options options, DocTracker docTracker) at CCDoc.CCDoc.RealMain(String[] args) at CCDoc.CCDoc.Main(String[] args) elapsed time: 1341.6023ms C:\Program Files (x86)\Microsoft\Contracts\MsBuild\v4.0\Microsoft.CodeContracts.targets(611,5): error MSB3073: The command ""C:\Program Files (x86)\Microsoft\Contracts\Bin\ccdocgen" "@obj\Debug\Stress.Logging.Commonccdocgen.rsp"" exited with code 1. -
11 martie 2012 22:34Proprietar
@Dave: Thanks for the repro. I found the problem and have fixed it. It will appear in the next release.
@Brian: If you can send me a repro, then I can make sure it works for your case as well.
Mike Barnett
- Propus ca răspuns de Mike BarnettMicrosoft Employee, Owner 11 martie 2012 22:34
- Marcat ca răspuns de Dave Sexton 11 martie 2012 22:44