Search code examples
mono.cecilcoverlet

coverlet: Unable to instrument module (ArgumentException)


I faced an issue when some projects from solution (NOT ALL) are not being instrumented (have zero coverage, though have active unit tests). All projects in solution have the same package refs and settings:

  1. coverlet: 3.2.0
  2. xUnit: 2.4.2
  3. MSFT.Net.Test.SDK: 16.6.1
  4. .net core 3.1

Run using following config (played with other settings with no luck):

dotnet.exe test c:\TestProject.csproj --collect "XPlat Code Coverage" --results-directory C:\CodeCoverage --configuration Release

After some investigation with --diag enabled, I got the following in the logs:

[coverlet]Unable to instrument module: C:\Development\EBH\RefreshAPI\src\EBillingHub.InvoiceExtraction.Business.Logic.Tests.Unit\bin\Release\netcoreapp3.1\EBillingHub.InvoiceExtraction.Business.Logic.dll System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection. at System.Buffer.BlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count) at Mono.Cecil.Metadata.GuidHeap.Read(UInt32 index) at Mono.Cecil.MetadataReader.InitializeCustomDebugInformations() at Mono.Cecil.MetadataReader.GetCustomDebugInformation(ICustomDebugInformationProvider provider) at Mono.Cecil.Cil.PortablePdbReader.ReadModule() at Mono.Cecil.Cil.PortablePdbReader.ProcessDebugHeader(ImageDebugHeader header) at Mono.Cecil.ModuleDefinition.ReadSymbols(ISymbolReader reader, Boolean throwIfSymbolsAreNotMaching) at Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition module, ReaderParameters parameters) at Mono.Cecil.ModuleReader.CreateModule(Image image, ReaderParameters parameters) at Mono.Cecil.ModuleDefinition.ReadModule(Disposable1 stream, String fileName, ReaderParameters parameters) at Mono.Cecil.ModuleDefinition.ReadModule(Stream stream, ReaderParameters parameters) at Coverlet.Core.Instrumentation.Instrumenter.CreateReachabilityHelper() in //src/coverlet.core/Instrumentation/Instrumenter.cs:line 203 at Coverlet.Core.Instrumentation.Instrumenter.InstrumentModule() in //src/coverlet.core/Instrumentation/Instrumenter.cs:line 209 at Coverlet.Core.Instrumentation.Instrumenter.Instrument() in //src/coverlet.core/Instrumentation/Instrumenter.cs:line 153 at Coverlet.Core.Coverage.PrepareModules() in //src/coverlet.core/Coverage.cs:line 135 TpTrace Warning: 0 : 22036, 1, 2023/03/16, 17:52:05.273, 364420612049, datacollector.dll, [coverlet]Unable to instrument module: C:\Development\EBH\RefreshAPI\src\EBillingHub.InvoiceExtraction.Business.Logic.Tests.Unit\bin\Release\netcoreapp3.1\EBillingHub.InvoiceExtraction.BusinessLogic.dll System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection. at System.Buffer.BlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count) at Mono.Cecil.Metadata.GuidHeap.Read(UInt32 index) at Mono.Cecil.MetadataReader.InitializeCustomDebugInformations() at Mono.Cecil.MetadataReader.GetCustomDebugInformation(ICustomDebugInformationProvider provider) at Mono.Cecil.Cil.PortablePdbReader.ReadModule() at Mono.Cecil.Cil.PortablePdbReader.ProcessDebugHeader(ImageDebugHeader header) at Mono.Cecil.ModuleDefinition.ReadSymbols(ISymbolReader reader, Boolean throwIfSymbolsAreNotMaching) at Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition module, ReaderParameters parameters) at Mono.Cecil.ModuleReader.CreateModule(Image image, ReaderParameters parameters) at Mono.Cecil.ModuleDefinition.ReadModule(Disposable1 stream, String fileName, ReaderParameters parameters) at Mono.Cecil.ModuleDefinition.ReadModule(Stream stream, ReaderParameters parameters) at Coverlet.Core.Instrumentation.Instrumenter.CreateReachabilityHelper() in //src/coverlet.core/Instrumentation/Instrumenter.cs:line 203 at Coverlet.Core.Instrumentation.Instrumenter.InstrumentModule() in //src/coverlet.core/Instrumentation/Instrumenter.cs:line 209 at Coverlet.Core.Instrumentation.Instrumenter.Instrument() in //src/coverlet.core/Instrumentation/Instrumenter.cs:line 153 at Coverlet.Core.Coverage.PrepareModules() in //src/coverlet.core/Coverage.cs:line 135

Tried to briefly check at Cecil repo what could have caused this, seems like it is related to some GUID, but can hardly understand which.

 sealed class GuidHeap : Heap {

public GuidHeap (byte [] data)
    : base (data)
{
}

public Guid Read (uint index)
{
    const int guid_size = 16;

    if (index == 0 || ((index - 1) + guid_size) > data.Length)
        return new Guid ();

    var buffer = new byte [guid_size];

    Buffer.BlockCopy (this.data, (int) ((index - 1) * guid_size), buffer, 0, guid_size);

    return new Guid (buffer);
} }

One interesting note: when I change project name, build and then rename it back (w/o cleaning, so 2 dll with diff name exist) - it instruments renamed dll and generates coverage for it.

Does anybody know about this issue? Maybe some workaround exists?


Solution

  • Problem was in some conflict between coverlet and PostSharp, probably because the latter one was added to the project but not used. Removing package fixed the issue