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

Notification

Icon
Error

ccrewrite (0)#0: Rewrite aborted due to metadata errors. Check output window
GreenMoose
#1 Posted : Sunday, July 8, 2012 7:58:45 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 503

Thanks: 142 times
Was thanked: 66 time(s) in 64 post(s)
[1.40.0.24b]

Trying to get NCrunch to play nicely with my solution with code contracts (for the NCrunch config, only runtime enabled and "Contract Reference Assembly" set to DoNotBuild).

I started to receive the following build errors, I can build same configuration just fine in vstudio 2010 and via msbuild.exe in command prompt.

The error NCrunch is reporting:
ccrewrite (0)#0: Rewrite aborted due to metadata errors. Check output window
C:\Program Files (x86)\Microsoft\Contracts\MsBuild\v4.0\Microsoft.CodeContracts.targets (245)#1: The command ""C:\Program Files (x86)\Microsoft\Contracts\Bin\ccrewrite" "@MYPROJECTNAMEccrewrite.rsp"" exited with code -1.

Any clues?
Remco
#2 Posted : Monday, July 9, 2012 2:10:28 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi, thanks for posting!

Does the project build correctly in NCrunch if you turn off the 'Allow dynamic code contract checking' option in your NCrunch project-level configuration? What happens if you enable the 'Allow static code contract checking' option?

When you built your project via the command prompt with msbuild.exe, did you need to inject any extra properties (such as 'Configuration')?.

Something also worth trying is to run the command line MSBuild inside the workspace NCrunch has built for your project, against the .proj file that NCrunch has generated for the build. You can find this by right-clicking on the failed project inside the Tests Window and choosing Advanced->Browse to workspace. Knowing whether it works within the workspace is very useful as we can deduct whether the problem is caused by the workspacing itself or NCrunch's build integration.
GreenMoose
#3 Posted : Tuesday, July 10, 2012 5:32:07 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 503

Thanks: 142 times
Was thanked: 66 time(s) in 64 post(s)
Worth noting is that the project does have a dll file in the NCrunch workspace so the build seems to work?

>Does the project build correctly in NCrunch if you turn off the 'Allow dynamic code contract checking' option in your NCrunch project-level configuration?
Yes

>What happens if you enable the 'Allow static code contract checking' option?
Same error

>When you built your project via the command prompt with msbuild.exe, did you need to inject any extra properties (such as 'Configuration')?.
Yes (msbuild MYSOLUTION.sln /p:"platform=any cpu" /p:"configuration=debug ncrunch")

>Something also worth trying is to run the command line MSBuild inside the workspace NCrunch has built for your project, against the .proj file that NCrunch has generated for the build.

Hrm in the workspace I get error below. The repositories project is referencing the DataModel project, which in turn has a reference to Iesi.Collections.
So the workaround I use now is referencing Iesi.Collections within the Repositories project as well. Thanks.
Quote:

Build started 2012-07-10 07:23:21.
Project "C:\Users\MYUSER\AppData\Local\NCrunch\6500\25\Infrastructure\APPNAME.Infrastructure.Repositories\APPNAME.Infrastructure.Repositories.csproj" on node 1 (default targets).
GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
CoreCompile:
Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
CodeContractRewrite:
"C:\Program Files (x86)\Microsoft\Contracts\Bin\ccrewrite" "@APPNAME.Infrastructure.Repositoriesccrewrite.rsp"
Reading assembly 'APPNAME.Domain.DataModel' from 'C:\Users\MYUSER\AppData\Local\NCrunch\6500\5\Domain\APPNAME.Domain.DataModel\bin\Debug NCrunch\APPNAME.Domain.DataModel.dll' resulted in errors.
Assembly reference not resolved: Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.
Could not resolve type reference: [Iesi.Collections]Iesi.Collections.Generic.ISet`1.
ccrewrite : error : Rewrite aborted due to metadata errors. Check output window [C:\Users\MYUSER\AppData\Local\NCrunch\6500\25\Infrastructure\APPNAME.Infrastructure.Repositories\APPNAME.Infrastructure.Repositories.csproj]
elapsed time: 3512,2009ms
C:\Program Files (x86)\Microsoft\Contracts\MsBuild\v4.0\Microsoft.CodeContracts.targets(245,5): error MSB3073: The command ""C:\Program Files (x86)\Microsoft\Contracts\Bin\ccrewrite" "@APPNAME.Infrastructure.Repositoriesccrewrite.rsp"" exited with code -1. [C:\Users\MYUSER\AppData\Local\NCrunch\6500\25\Infrastructure\APPNAME.Infrastructure.Repositories\APPNAME.Infrastructure.Repositories.csproj]
Done Building Project "C:\Users\MYUSER\AppData\Local\NCrunch\6500\25\Infrastructure\APPNAME.Infrastructure.Repositories\APPNAME.Infrastructure.Repositories.csproj" (default targets) -- FAILED.



*Edit: But now the nCrunch.TestHost.x86.exe starts crashing for tests where the code contracts throw System.Diagnostics.Contracts.__ContractsRuntime+ContractException .
Remco
#4 Posted : Tuesday, July 10, 2012 6:15:34 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Nice working on identifying the indirect dependency. Most likely the code contracts rewriter was expecting the indirect dependency to exist in the same directory as the project being built, which would probably only be the case if the 'Copy referenced assemblies to workspace' setting was enabled.

The crashing on ContractException isn't something that can be controlled or handled by NCrunch. Basically this is behaviour that is introduced by code contracts in order to enforce contract adherence at runtime. I think there is a way that you can turn this behaviour off in your code contracts settings (though I'm far from an expert on code contracts myself).
GreenMoose
#5 Posted : Tuesday, July 10, 2012 8:12:23 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 503

Thanks: 142 times
Was thanked: 66 time(s) in 64 post(s)
Remco;2412 wrote:
Most likely the code contracts rewriter was expecting the indirect dependency to exist in the same directory as the project being built, which would probably only be the case if the 'Copy referenced assemblies to workspace' setting was enabled.

It did not help enabling this property unfortunately.

Remco;2412 wrote:
The crashing on ContractException isn't something that can be controlled or handled by NCrunch. Basically this is behaviour that is introduced by code contracts in order to enforce contract adherence at runtime. I think there is a way that you can turn this behaviour off in your code contracts settings (though I'm far from an expert on code contracts myself).

Actually debugging this showed that the exception thrown was a System.ExecutionEngineException. So I started investigating and added an event handler for Contract.ContractFailed but it did not help (I avoided NCrunch crashes if I did not throw any exception in the handler at all but then the tests failed since they expected an exception).
Eventually I commented out the contract failed event handler and suddenly NCrunch stops crashing and now it seems to work fine, very weird :/.
1 user thanked GreenMoose for this useful post.
Remco on 7/11/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.042 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download