Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

exception when using Code Contracts
4rchie
#1 Posted : Thursday, November 10, 2011 1:07:43 PM(UTC)
Rank: Member

Groups: Registered
Joined: 10/12/2011(UTC)
Posts: 27
Location: Poland

Thanks: 2 times
Was thanked: 6 time(s) in 6 post(s)
I've just tried to use Code Contracts in my application. As soon as I've enabled that feature of c# 4.0 I got a big window with message:


nCrunch.TaskRunner40.x86.exe - Assert Failure

Description: Must use the rewriter when using Contract.Ensures
Stack Trace:
at System.Diagnostics.Contracts.Contract.AssertMustUseRewriter(ContractFailureKind kind, String contractKind)

at System.Diagnostics.Contracts.Contract.Ensures(Boolean condition)

at ClassLibrary2.Class1.Dodawanie(Int32 a, Int32 b)

at ClassLibrary2.Class1.TestName()

at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)

at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)

at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

at Gallio.Common.Diagnostics.ExceptionUtils.InvokeMethodWithoutTargetInvocationException(MethodBase method, Object obj, Object[] args)

at Gallio.Framework.Pattern.PatternTestInstanceState.InvokeTestMethod()

at MbUnit.Framework.TestAttribute.Execute(PatternTestInstanceState state)

at Gallio.Framework.Pattern.PatternTestExecutor.ExecuteTestInstanceAction.Run()

at Gallio.Common.Concurrency.ThreadAbortScope.Run(Action action)

at Gallio.Framework.Sandbox.Run(MarkupDocumentWriter markupDocumentWriter, Action action, String description)

at Gallio.Framework.Pattern.PatternTestExecutor.RunTestInstanceAction.Run()

at Gallio.Framework.Pattern.PatternTestExecutor.RunTestDataItemAction.Run()

at Gallio.Framework.Pattern.PatternTestExecutor.RunTestAction.Run()

at Gallio.Framework.Pattern.PatternTestExecutor.RunTestInstanceAction.Run()

at Gallio.Framework.Pattern.PatternTestExecutor.RunTestDataItemAction.Run()

at Gallio.Framework.Pattern.PatternTestExecutor.RunTestAction.Run()

at Gallio.Framework.Pattern.PatternTestExecutor.RunTestInstanceAction.Run()

at Gallio.Framework.Pattern.PatternTestExecutor.RunTestDataItemAction.Run()

at Gallio.Framework.Pattern.PatternTestExecutor.RunTestAction.Run()

at Gallio.Framework.Pattern.PatternTestController.RunImpl(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)

at Gallio.Model.Helpers.DelegatingTestController.RunTest(ITestCommand testCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)

at Gallio.Model.Helpers.DelegatingTestController.RunTest(ITestCommand testCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)

at Gallio.Model.Helpers.DelegatingTestController.RunImpl(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)

at Gallio.Model.Helpers.SimpleTestDriver.RunTestCommandsAction.Run()

at Gallio.Model.Helpers.SimpleTestDriver.RunAssembly(Assembly assembly, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)

at Gallio.Model.DotNetTestDriver.ExploreOrRunTask.ExploreOrRun(Type driverType, Object[] driverArguments, String assemblyPath, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor, Boolean useSynchronousMessaging)

at Gallio.Model.DotNetTestDriver.ExploreOrRunTask.RunImpl(Object[] args)

at Gallio.Model.Isolation.IsolatedTask.Run(Object[] args)

at nCrunch.GallioIntegration.NCrunchTestIsolationContext.InvokeTask[TIsolatedTask](IHost host, TIsolatedTask isolatedTask, Object[] args)

at Gallio.Model.Isolation.HostedTestIsolationContext.RunIsolatedTaskInHost[TIsolatedTask](HostSetup hostSetup, StatusReporter statusReporter, Object[] args)

at Gallio.Model.Isolation.HostedTestIsolationContext.RunIsolatedTaskImpl[TIsolatedTask](HostSetup hostSetup, StatusReporter statusReporter, Object[] args)

at Gallio.Model.Isolation.BaseTestIsolationContext.RunIsolatedTask[TIsolatedTask](HostSetup hostSetup, StatusReporter statusReporter, Object[] args)

at Gallio.Model.DotNetTestDriver.ExploreOrRunAssembly(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, RemoteMessageSink remoteMessageSink, IProgressMonitor progressMonitor, String taskName, FileInfo file)

at Gallio.Model.DotNetTestDriver.ExploreOrRun(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor, String taskName)

at Gallio.Model.DotNetTestDriver.RunImpl(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)

at Gallio.Model.BaseTestDriver.Run(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)

at Gallio.Model.DefaultTestFrameworkManager.FilteredTestDriver.<>c__DisplayClass1f.<RunImpl>b__1d(ITestDriver driver, IList`1 items, Int32 driverCount)

at Gallio.Model.DefaultTestFrameworkManager.FilteredTestDriver.ForEachDriver[T](MultiMap`2 testFrameworkPartitions, Func`4 func)

at Gallio.Model.DefaultTestFrameworkManager.FilteredTestDriver.RunImpl(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)

at Gallio.Model.BaseTestDriver.Run(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)

at Gallio.Runner.DefaultTestRunner.Run(TestPackage testPackage, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IProgressMonitor progressMonitor)

at nCrunch.TestExecution.Frameworks.Gallio.GallioTestFramework.#=qP8mqIFwTfEa9WIBfpa5D3qCoKglIKVshOQCFQ$7b7dw=.#=qMvas4948MaQS4aPjrWtf2g==()

at #=qmdEAMK_c0wUkjl8QiR_0B$SqavkVGH8_WBLRdXnGACXX4ij_QGiQi6Yyi3LkqyId.#=qM5vw4cReHtB0oIZAADXisWrKqcIWrMteVT2lL5CSY$Y=(Action #=qQG$$IEqJNd7U57rti2oO0eMOr5L73KqDbcsBxL9FrLo=)

at nCrunch.TestExecution.Frameworks.Gallio.GallioTestFramework.RunTests(TestOutput output, IList`1 testsToRun, MasterExecutionMapSet masterMapSet)

at nCrunch.TestExecution.TestRunnerThread.#=qh9mHFD74qNv_qxnwJeExOA==(IMasterExecutionMap[] #=qk1TQlxFS2PvZulTUk4olrnb6ZWeHHkBAUGvy2pOCQ04=, IList`1 #=q_93JaZI9Uj9vyZ1g2aaI8Q==)

at nCrunch.TestExecution.TestRunnerThread.#=qMatA7O7HNDNftSAGqk$zXwsRyZMSQlaG4AK$V7qYeZE=()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.runTryCode(Object userData)

at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)

at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()



Press RETRY to attach debugger




Regards,
4rchie
Remco
#2 Posted : Thursday, November 10, 2011 8:52:24 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Does it make any difference if you turn on the 'CopyReferencedAssembliesToWorkspace' option for your tests project?
4rchie
#4 Posted : Monday, November 14, 2011 8:08:28 AM(UTC)
Rank: Member

Groups: Registered
Joined: 10/12/2011(UTC)
Posts: 27
Location: Poland

Thanks: 2 times
Was thanked: 6 time(s) in 6 post(s)
Changing CopyReferencedAssemblies does not solve the problem. I've wrote a little project that shows the error.

http://speedy.sh/AQwSw/C...ctFailingWithNCover.zip


Changing CopyReferencedAssemblies throws the big error message box like above.
Remco
#5 Posted : Monday, November 14, 2011 9:02:52 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Excellent thanks - I'll take a look at the sample and will get back to you.
4rchie
#6 Posted : Monday, November 14, 2011 10:36:27 AM(UTC)
Rank: Member

Groups: Registered
Joined: 10/12/2011(UTC)
Posts: 27
Location: Poland

Thanks: 2 times
Was thanked: 6 time(s) in 6 post(s)
Remco;585 wrote:
Excellent thanks - I'll take a look at the sample and will get back to you.


no problem, take your time. It's not stopping me so its not a priority for me and I have'nt seen others to report that :)
JohnStov
#7 Posted : Tuesday, November 15, 2011 9:41:35 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 10/31/2011(UTC)
Posts: 7

Thanks: 1 times
Was thanked: 3 time(s) in 3 post(s)
I think Code Contracts may also be causing NCrunch to build really slowly for me.

I have quite a simple solution (3 smallish projects) that builds with Code Contracts. I only have runtime contract 7checking enabled for all the projects.

When I enable NCrunch, the NCrunch process build the solution, and then (looking in Task Manager) ccrewrite and then cccheck run, and load the CPU for a very long time.

The end result is that NCruncH takes minutes longer to build and run my tests than Resharper does.

Any suggestions/workarounds? I'd like to be able to use NCrunch with Code Contracts, but at the moment they seem incompatible.

Thanks in advance.
Remco
#8 Posted : Wednesday, November 16, 2011 10:01:22 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
I'm not sure if there's much that can be done about this.

Code contracts wasn't written with the idea of continuous testing in mind. Mechanically the way it works is actually quite evil - it infers logic across output assemblies being in the same directory, which requires NCrunch to force itself to turn on the CopyReferencedAssembliesToWorkspace setting for all applicable projects in your solution... this in turn means NCrunch is unable to perform properly optimised builds while you make changes, and it will slow your response times.

The only solution I could offer would be to turn off code contracts for your NCrunch builds. You can do this by adding a condition to the code contracts build property in your .proj file by using the $(NCrunch) variable.
1 user thanked Remco for this useful post.
JohnStov on 11/18/2011(UTC)
JohnStov
#9 Posted : Friday, November 18, 2011 11:49:45 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 10/31/2011(UTC)
Posts: 7

Thanks: 1 times
Was thanked: 3 time(s) in 3 post(s)
Thanks,

I'll give that a try.
Remco
#10 Posted : Monday, November 21, 2011 7:38:05 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Hi Archie,

I've taken a look at the issue you're experiencing with Code Contracts and I'm wondering if this may be due to your code contracts configuration.

When I try running your test solution through any test runner, I receive the same result (as you've described at the top of this thread). I'm far from an expert on code contracts, but is it possible that you need to switch on the rewriter in the code contracts configuration for this to work correctly? I'm not sure what I can do from the side of NCrunch to make this work.


Thanks!

Remco
4rchie
#11 Posted : Wednesday, November 23, 2011 8:12:01 AM(UTC)
Rank: Member

Groups: Registered
Joined: 10/12/2011(UTC)
Posts: 27
Location: Poland

Thanks: 2 times
Was thanked: 6 time(s) in 6 post(s)
Im not an expert on code contracts as well. This error shows up when I don't install the Code Contracts Vs adddon so you're probably not far from the truth with the rewriter. However it is strange for me that I get big error message window from NCover. If it is possible I would stream that error to the NCover log instead of throwing it out to the screen.

Regards,
Archie
Remco
#12 Posted : Wednesday, November 23, 2011 10:08:04 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
It looks to me like the error message that's being raised is done so by the code under test itself ... so there isn't really much I can do about this. Though I definitely take your point - it is extremely annoying!
4rchie
#13 Posted : Wednesday, November 23, 2011 1:40:48 PM(UTC)
Rank: Member

Groups: Registered
Joined: 10/12/2011(UTC)
Posts: 27
Location: Poland

Thanks: 2 times
Was thanked: 6 time(s) in 6 post(s)
if we talk about my code, then I do not raise any error messages windows so it must be somewhere in the Code Contracts itself...... conclusion: we're screwed :D
Remco
#14 Posted : Wednesday, November 23, 2011 10:22:43 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Did you have much luck with implementing the build switch to turn it off? There may be a way of making this more sophisticated so as to only use code contracts when it's actually installed - if you can find a build condition that can identify this scenario .. then just turn off the CONTRACTS_FULL property. This will probably help you with other testing frameworks too.
Akim
#15 Posted : Saturday, March 17, 2012 11:21:49 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/17/2012(UTC)
Posts: 7

Thanks: 2 times
Was thanked: 2 time(s) in 2 post(s)
I have similar issue with Code Contract and nCrunch, and I found both of them quite useful for my project.
So I create separate solution configuration in Visual Studio for nCrunch without Code Code Contract, and make nCrunch using only this configuration via Ncrunch->Setting for every project.

Configuration for nCrunch w/o Code Contract
1 user thanked Akim for this useful post.
Remco on 3/17/2012(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.162 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download