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

Notification

Icon
Error

Cecil failure during test project build
brunellus
#1 Posted : Friday, September 23, 2016 1:33:48 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/28/2016(UTC)
Posts: 2
Location: Czech Republic

Hello, NCrunch fails with the following message in one of our test projects:

System.NotSupportedException: Specified method is not supported.
at _Mono.Cecil.MetadataReader.ReadVariables(MetadataToken local_var_token)
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 )

I wonder what can we do -- how to locate the exact code that is triggering this error, for example.
Remco
#2 Posted : Friday, September 23, 2016 11:58:58 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi, thanks for sharing this issue.

This particular exception is being thrown because of a method variable that has an unexpected (invalid?) signature in the assembly's IL. It's possible that this is due to a method in your assembly having an unusual structure, or otherwise it could be a downstream problem from some kind of IL corruption that Cecil is sensitive to but the JIT is not.

Did this problem start appearing suddenly? Or is this the first time you're using NCrunch on this project?

Which version of Visual Studio and .NET are you using?

Are you performing any kind of post-build manipulation of this assembly? (i.e. mocking frameworks, MSFakes, code contracts, Frody, postsharp, etc).
brunellus
#3 Posted : Sunday, September 25, 2016 4:32:50 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/28/2016(UTC)
Posts: 2
Location: Czech Republic

This is something that started to appear with growth of the test project. For the record, we use VS 2015, the test library is for .NET Framework 4.5.2. There is no IL postprocessing, I think.

I wrote this code to test what may be causing it:

var assembly = AssemblyDefinition.ReadAssembly(@"C:\Source\...\test.dll", new ReaderParameters { ReadSymbols = true });
var module = assembly.MainModule;

foreach (var type in module.Types)
{
foreach (var method in type.Methods)
{
try
{
var body = method.Body;
}
catch (NotSupportedException ex)
{
Console.WriteLine($"NotSupported: {method.FullName}");
}
catch (NotImplementedException ex)
{
Console.WriteLine($"NotImplemented: {method.FullName}");
}
}
}

There are lots of methods that throw NotSupported and few that throws NotImplemented. Interestingly, when I gradually remove code from the test project, at one point all the issues disappear, even ones previously reported in code that is still there. Very strange. But, all this happens when I use latest stable Cecil nuget (0.9.6.4), but no exceptions are thrown when running against unstable 0.10.0-beta1-v2. So this is probably an already fixed issue.

I guess I can only hope that you update your Cecil sooner than later after 0.10 stabilizes. :-) This is not critical for us, it affects only one from many projects.
Remco
#4 Posted : Sunday, September 25, 2016 11:34:28 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
brunellus;9195 wrote:
This is something that started to appear with growth of the test project. For the record, we use VS 2015, the test library is for .NET Framework 4.5.2. There is no IL postprocessing, I think.
There are lots of methods that throw NotSupported and few that throws NotImplemented. Interestingly, when I gradually remove code from the test project, at one point all the issues disappear, even ones previously reported in code that is still there. Very strange. But, all this happens when I use latest stable Cecil nuget (0.9.6.4), but no exceptions are thrown when running against unstable 0.10.0-beta1-v2. So this is probably an already fixed issue.

I guess I can only hope that you update your Cecil sooner than later after 0.10 stabilizes. :-) This is not critical for us, it affects only one from many projects.


Thanks for taking the effort to narrow this down. I've had a bit of a run through the latest Cecil changes to try and figure out what may be causing this. Unfortunately, the problem doesn't look to be simple :(

I think there is something unexpected/corrupt in this assembly at a fairly fundamental level. Cecil 0.10 has seen 1.5 years of development over the last stable release, so I don't think there is much chance of finding this with a code review. To have any chance of fixing this problem I'll need to get hold of an assembly that can reproduce it. Let me know if you find an isolated way to reproduce the problem or if you're able to share a sample with me that I can work with.
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.038 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download