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

Notification

Icon
Error

NCrunch Issue with NuGet Package with Generic
ericschmidt
#1 Posted : Tuesday, February 14, 2017 1:01:45 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/30/2016(UTC)
Posts: 8
Location: United States of America

I am having a problem with a project not building in NCrunch. It seems to be similar to this post (http://forum.ncrunch.net/yaf_postsm4052_Issue-when-using-NCrunch-with-Code-Contracts-and-Fody.aspx#post4052), but it's an internally developed NuGet package, where I just implemented a generic class. When I try to implement this generic abstract class in one of my projects, I get the following Exception message below. This only happens in NCrunch. I even removed the generic class in our NuGet project and NCrunch was able to build the project as expected.

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
at _Mono.Collections.Generic.Collection`1..ctor(Int32 capacity)
at _Mono.Cecil.Cil.CodeReader.ReadCode()
at _Mono.Cecil.Cil.CodeReader.ReadFatMethod()
at _Mono.Cecil.Cil.CodeReader.ReadMethodBody()
at _Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
at _Mono.Cecil.MethodDefinition.<>c.<get_Body>b__36_0(MethodDefinition method, MetadataReader reader)
at _Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
at _Mono.Cecil.MethodDefinition.get_Body()
at nCrunch.Reflection.Cecil.CecilMethod.get_HasBody()
at nCrunch.TestExecution.Frameworks.DefaultClassMethodDescriptionLocator.ExtractClassMemberDataFromType(ReflectedType type, Boolean hashAllMethods)
at nCrunch.Compiler.StaticManipulation.BuiltAssembly.(ReflectedAssembly , IDictionary`2 , TestFrameworkDescription[] , Boolean )
at nCrunch.Compiler.StaticManipulation.BuiltAssembly.ExtractClassMethodData(TestFrameworkDescription[] applicableTestFrameworks, IDictionary`2 codeFileIDsByFilePath, Boolean hashMethods)
at nCrunch.Compiler.RemoteBuildRunner..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.Compiler.RemoteBuildRunner.(ComponentBuildParameters , FilePath , BuildOutput , DirectoryPath[] , FilePath[] )
at nCrunch.Compiler.RemoteBuildRunner..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.Compiler.RemoteBuildRunner.(ComponentBuildParameters )
Remco
#2 Posted : Tuesday, February 14, 2017 7:07:48 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 587 times
Was thanked: 667 time(s) in 638 post(s)
Hi, thanks for sharing this issue.

This looks to be caused by a particular IL sequence that NCrunch isn't able to handle. Are you able to reproduce this in a project that you can share with me?
ericschmidt
#3 Posted : Monday, February 27, 2017 4:24:18 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/30/2016(UTC)
Posts: 8
Location: United States of America

I'm trying to create a small sample to reproduce. Do you just need a sample of the project that is unable to build or would you need a sample of a NuGet package that also causes this issue?
Remco
#4 Posted : Monday, February 27, 2017 10:09:33 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 587 times
Was thanked: 667 time(s) in 638 post(s)
Ideally a sample of the project itself with any dependencies required to build it. I might be able to reproduce it with just the compiled DLL for this project, but a full code sample with dependencies will usually give certainty that I can reproduce the problem and produce a proper test case for it.

You're welcome to submit any code through the contact form at https://www.ncrunch.net/support/contact.
ericschmidt
#5 Posted : Tuesday, May 09, 2017 5:02:48 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/30/2016(UTC)
Posts: 8
Location: United States of America

My apologies for the severely delayed response. I had updated NCrunch and thought that corrected the issue I was seeing, but it turns out that I just hadn't implemented the inheritance. After several attempts, I was able to reproduce the issue using a smaller sample. Following your directions, I submitted the sample through the contact link you provided. I think I've also narrowed the issue down a little further. The exception is only thrown when we obfuscate the NuGet package, which we're doing to protect IP.
Remco
#6 Posted : Tuesday, May 09, 2017 11:21:28 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 587 times
Was thanked: 667 time(s) in 638 post(s)
Thanks for coming back to this one! For some reason, the sample didn't make it through the contact link. Do you have any other way you can share it with me? Otherwise you could try emailing it to support at ncrunch dot net.
ericschmidt
#7 Posted : Tuesday, May 09, 2017 11:26:58 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/30/2016(UTC)
Posts: 8
Location: United States of America

I just sent an Email containing the projects. Let me know if you have any issues with them.
Remco
#8 Posted : Tuesday, May 09, 2017 11:29:57 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 587 times
Was thanked: 667 time(s) in 638 post(s)
Looks like it is coming through now. Thanks for your help. I'll get back to you as soon as I have more information.
Remco
#9 Posted : Wednesday, May 10, 2017 2:12:46 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 587 times
Was thanked: 667 time(s) in 638 post(s)
Thanks for the sample solution. It's very useful that you were able to submit all components relevant to the problem. I appreciate the effort it would have taken you to whittle this down.

The problem appears to be caused by the obfuscation of the NuGet package. The obfuscator being used here appears to be designed to create an assembly that is structurally invalid in a way that cannot be processed by IL manipulation tools but can still be executed by the CLR.

After NCrunch builds your project, it loads the freshly built assembly into memory and generates a series of hashes from the assembly content that are later used for impact analysis. This allows NCrunch to detect when changes are made to the assembly's IL so that the appropriate tests can be run intelligently. Because this assembly inherits from a type in the Nuget package, the obfuscated Nuget package assembly also needs to be loaded and considered by the hash routine. This results in obfuscated code being read from an invalid assembly and an exception is thrown.

Unfortunately I can't think of a reliable way for me to introduce a workaround for this in NCrunch itself. This is because the assembly is actually invalid and designed not to be read by anything but the CLR itself. It might be possible to rig NCrunch to simply ignore assemblies that it has problems reading, but this would not be a stable solution as the data could also be read incorrectly, resulting in strange downstream problems.

There are several ways you can work around this problem:
1. Consider compiling the Nuget package without the obfuscator for use in your NCrunch environment
2. Set your 'Impact detection mode' solution-level NCrunch setting to 'Watch Text'. This will disable IL-hashing for impact detection purposes, so the obfuscated assembly may not need to be loaded.
3. Consider using a different obfuscator that can still protect your code without structurally invalidating the assembly itself. Your existing obfuscator may also have configuration options allowing you to choose the features you want to use for obfuscation.
4. Avoid inheriting from types in the Nuget package. It might be possible to use the package through referencing code elements as long as you avoid inheritance (I haven't tested this).
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.049 seconds.