Build/Test Issues

Optional argument causes build error when PCL does not target Silverlight

Started by yanglee on 9,587 views

NCrunch 1.42.0.12
VS2012
Windows 8 64bit

This is a similar issue to this one: Portable class libraries fail to build if they include metro

Resharper and the built in test runner of VS2012 works fine. I tested some classes as optional argument and found only String and user created classes don't cause this issue.

Steps to reproduce the issue:

1) Create a Portable Class Library;
2) Remove Silverlight as target platform;
3) Add the following class:

    public class MyClass
    {
        public void DoSomething(Type arg = null)
        {
        }
    }


4) Enable NCrunch. I get the following build error:

[13:04:19.2936-BuildTask-7] ERROR (Compilation): PortableClassLibrary1:  (0): System.InvalidOperationException: Failed to resolve type: System.Type
   at Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
   at Mono.Cecil.MetadataBuilder.GetConstantType(TypeReference constant_type, Object constant)
   at Mono.Cecil.MetadataBuilder.AddConstant(IConstantProvider owner, TypeReference type)
   at Mono.Cecil.MetadataBuilder.AddParameter(UInt16 sequence, ParameterDefinition parameter, ParamTable table)
   at Mono.Cecil.MetadataBuilder.AddParameters(MethodDefinition method)
   at Mono.Cecil.MetadataBuilder.AddMethod(MethodDefinition method)
   at Mono.Cecil.MetadataBuilder.AddMethods(TypeDefinition type)
   at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
   at Mono.Cecil.MetadataBuilder.AddTypeDefs()
   at Mono.Cecil.MetadataBuilder.BuildTypes()
   at Mono.Cecil.MetadataBuilder.BuildModule()
   at Mono.Cecil.ModuleWriter.<BuildMetadata>b__0(MetadataBuilder builder, MetadataReader _)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
   at Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata)
   at Mono.Cecil.ModuleWriter.WriteModuleTo(ModuleDefinition module, Stream stream, WriterParameters parameters)
   at Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters)
   at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
   at nCrunch.Compiler.StaticManipulation.BuiltAssembly.#=qVVxyPFyV07SGmGwvnqJ58GP1CjxFAgHrcNQX4zelNig=.#=qVhwsrVPHh0cRHCRNhV_dH0P51C3c8nYxqUsFAc9QohE=()
   at nCrunch.Compiler.StaticManipulation.BuiltAssembly.#=qxEWPuumRjENxBqFDuwVIPQ==(Action #=qNFebLMPvzAnxbLsp9k2cSw==)
   at nCrunch.Compiler.StaticManipulation.BuiltAssembly.Instrument(ComponentSourceLineMap sourceLineMap, IDictionary`2 instrumentationDirectivesByCodeFileId, IDictionary`2 codeFileIDsByFilePath, Boolean proxyProcessIsActive, Int32 componentId, IInstrumentationFilter[] instrumentationFilters)
   at nCrunch.Compiler.RemoteBuildRunner.#=qPVZ1Qvt7K1dg$S2Tsbki14jXz55V81a4b0lw2Gy2H9I=(ComponentBuildParameters #=qaLbij$nvLcp1xzKxt0ECzQ==, String #=q3Qo9mUTR8Ej_efd8kOmuaRPOgcadukhysqWjzfCknIs=, BuildOutput #=qc1a02FFghipoiqbEEWdEuA==, String #=qib4s6fOXht5wNWFzsTveI52_75PbtixMjh7DSUYzHhg=)
   at nCrunch.Compiler.RemoteBuildRunner.Build(ComponentBuildParameters parameters)



Regards,

Yang

Edited

Hi Yang,

Thanks for reporting this problem - it looks to be very similar to a resolution issue that was fixed in 1.42, which suggests there is more to this issue than first thought. I'll see if I can arrange a fix for it in the next minor revision.


Cheers,

Remco
For anyone experiencing this problem, a potential workaround is to turn off the 'Instrument Output Assembly' setting for the project failing to build. Although this will turn off code coverage for the project, it should allow other depending projects in your solution to build and be processed normally.


Cheers,

Remco
Remco wrote:For anyone experiencing this problem, a potential workaround is to turn off the 'Instrument Output Assembly' setting for the project failing to build. Although this will turn off code coverage for the project, it should allow other depending projects in your solution to build and be processed normally.


Cheers,

Remco

Thanks, it works!
It appears turning off 'Instrument Output Assembly' not only turns off code coverage, but also causes another problem: When navigate to a source file via the stack trace of the Exception popup or NCrunch Tests window, a copied file in the NCrunch's workspace will be opened instead of the original source file in the solution folder.
This makes sense. The instrumentation step is also used to write the debugging information of the assembly so that it points back to the right place. There isn't an easy fix for this... I think I'd rather focus on the main issue that caused you to need to turn off this setting in the first place :)
For anyone interested, 1.43 has just been released with a fix for the above PCL build problem.

Post a reply

Log in to reply.