coverlet-coverage / coverlet

Cross platform code coverage for .NET
MIT License
2.94k stars 386 forks source link

Coverlet failing to instrument module [Mono.Cecil Exception] #1355

Closed skerr0 closed 2 years ago

skerr0 commented 2 years ago

Hello, I'm currently using coverlet on a wpf project with the following setup:

I have gone through the troubleshooting guide and have determined that my main executable in the project is failing to instrument. Other .net standard and .net framework libraries generate proper coverage results. This occurs when running coverlet either as collector or build. There is an exception thrown when instrumentation is attempted.

Any advice or suggestions would be appreciated

_TpTrace Warning: 0 : 35112, 1, 2022/06/22, 11:18:44.245, 4166831566790, datacollector.dll, [coverlet]Unable to instrument module: C:\Users\kerr\source\repos\VaxArraySoftware\VaxArraySoftware\InDevR.VaxArray.WPFTests\bin\x64\Debug\net48\InDevR.VaxArray.WPF.exe Mono.Cecil.ResolutionException: Failed to resolve System.Windows.Threading.DispatcherPriority 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.AddTypes() at Mono.Cecil.MetadataBuilder.BuildTypes() at Mono.Cecil.MetadataBuilder.BuildModule() at Mono.Cecil.MetadataBuilder.BuildMetadata() at Mono.Cecil.ModuleWriter.<>c.b__20(MetadataBuilder builder, MetadataReader ) at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func3 read) at Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata) at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable1 stream, WriterParameters parameters) at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters) at Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters) at Coverlet.Core.Instrumentation.Instrumenter.InstrumentModule() in //src/coverlet.core/Instrumentation/Instrumenter.cs:line 335 at Coverlet.Core.Instrumentation.Instrumenter.Instrument() in //src/coverlet.core/Instrumentation/Instrumenter.cs:line 145 at Coverlet.Core.Coverage.PrepareModules() in //src/coverlet.core/Coverage.cs:line 135

MarcoRossignoli commented 2 years ago

Can you try temporary to manually copy WindowsBase.dll to the bin folder? I think it's a dup of https://github.com/coverlet-coverage/coverlet/issues/1221

skerr0 commented 2 years ago

The executable which was failing to instrument does so now with the WindowsBase.dll added.

I don't mind applying this solution for local development, but Is the root cause planned to be addressed? Or is it potentially an issue with how my project is set up?

Thanks

MarcoRossignoli commented 2 years ago

It's planned but not yet on the right place in the queue of prio, you can check in the linked issue where's the problem.

We should add the Windows resolver to this list https://github.com/coverlet-coverage/coverlet/blob/master/src/coverlet.core/Instrumentation/CecilAssemblyResolver.cs#L75

We accept PR if you're interested, not mandatory.