jbevain/cecil

GetSequencePointMapping() throws Argument Exception

MNie opened this issue · 10 comments

MNie commented

It looks like GetSequencePointMapping method (line 675 or 682) tries to add a duplicate to a dictionary what results with a lock on an exe file.
Issue: Expecto.Adapter
Steps to reproduce:

  1. Create/Open F# project in Visual Studio
  2. Install Expecto ( > 5.0) and Adapter (> 5.0)
  3. run tests several times
  4. update/reinstall packages related to Expecto
  5. try to run specs

@adamchester

Thanks for reporting this. I'll need an exe and a pdb which reproduces the issue to diagnose the best fix.

MNie commented

Here You are :)
I also noticed that if project with specs is set to Console Application everything is correct. If it is set to a Class library this error occurs.

@jbevain

That's very curious! Thanks for the repro, I'll have a look!

MNie commented

Hi @jbevain!
How things are going on? Any information?

I think jb is travelling at the moment

I can't reproduce the issue with the binaries you provided. There's no method in ConsoleApplication.dll for which GetSequencePointMapping is throwing.

Closing this for now. Feel free to re-open with a repro.

Hello @jbevain .
Please look into this issue once again.
Here is the binary on which this issue is reproduced:
https://github.com/alex-bogomaz/ExpectoAdapterCecilIssue/blob/master/ExpectoAdapterCecilIssue/bin/Debug/ExpectoAdapterCecilIssue.dll .

Following code:

var readerParams = new ReaderParameters { ReadSymbols = true, InMemory = true };
var moduleDefinition = ModuleDefinition.ReadModule(@"D:\GitHub\alex-bogomaz\ExpectoAdapterCecilIssue\ExpectoAdapterCecilIssue\bin\Debug\ExpectoAdapterCecilIssue.dll", readerParams);
var types = moduleDefinition.GetTypes();

foreach (var t in types)
{
    foreach (var m in t.GetMethods())
    {
         var s = m.DebugInformation.GetSequencePointMapping();
    }
}

fails with exception:

  HResult=0x80070057
  Message=An item with the same key has already been added.
  Source=mscorlib
  StackTrace:
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at Mono.Cecil.Cil.MethodDebugInformation.GetSequencePointMapping()
   at ConsoleApp1.Program.Main(String[] args) in D:\My\Projects\PSlogger-master\ConsoleApp1\Program.cs:line 25

Erroneous MethodDefinition is:

Microsoft.FSharp.Core.Unit 
ExpectoAdapterCecilIssue.Tests/equality@16::Invoke(Microsoft.FSharp.Core.Unit)}

Software version:

<package id="Mono.Cecil" version="0.10.0-beta6" targetFramework="net461" />

Related ExpectoAdapter issue:
adamchester/expecto-adapter#28

@alex-bogomaz thanks for the repro!

@jbevain Can we get a NuGet package with this fix? Expecto VS adapter doesn't work without it.