Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverlet unable to instrument module after .NET 7 update #1404

Closed
mfisher214 opened this issue Nov 9, 2022 · 10 comments
Closed

Coverlet unable to instrument module after .NET 7 update #1404

mfisher214 opened this issue Nov 9, 2022 · 10 comments
Labels
needs more info More details are needed tracking-external-issue The issue is caused by external problem - nothing we can do to fix it directly

Comments

@mfisher214
Copy link

After update to dotnet 7, I am seeing these warnings at the beginning of our Test phase (they also appear on local when running dotnet test):

/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): warning : [coverlet] Unable to instrument module: /home/vsts/work/1/s/build/tests/Release/net7.0/(project file).dll [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): warning : System.IO.IOException: The process cannot access the file '/home/vsts/work/1/s/build/tests/Release/net7.0/(project file).pdb' because it is being used by another process. [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): warning : at Microsoft.Win32.SafeHandles.SafeFileHandle.Init(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Int64& fileLength, UnixFileMode& filePermissions) [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): warning : at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Func4 createOpenException) [/home/vsts/work/1/s/tests/dotnet/(project file).csproj] /home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): warning : at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable1 unixCreateMode) [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): warning : at System.IO.File.OpenWrite(String path) [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): warning : at Mono.Cecil.Cil.PortablePdbWriterProvider.GetSymbolWriter(ModuleDefinition module, String fileName) [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): warning : at Mono.Cecil.Cil.DefaultSymbolWriterProvider.GetSymbolWriter(ModuleDefinition module, String fileName) [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): warning : at Mono.Cecil.ModuleWriter.GetSymbolWriter(ModuleDefinition module, String fq_name, ISymbolWriterProvider symbol_writer_provider, WriterParameters parameters) [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): warning : at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable1 stream, WriterParameters parameters) [/home/vsts/work/1/s/tests/dotnet/(project file).csproj] /home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): warning : at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable1 stream, WriterParameters parameters) [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): warning : at Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters) [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): warning : at Coverlet.Core.Instrumentation.Instrumenter.InstrumentModule() in //src/coverlet.core/Instrumentation/Instrumenter.cs:line 337 [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): warning : at Coverlet.Core.Instrumentation.Instrumenter.Instrument() in /
/src/coverlet.core/Instrumentation/Instrumenter.cs:line 153 [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): warning : at Coverlet.Core.Coverage.PrepareModules() in //src/coverlet.core/Coverage.cs:line 135 [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): error : The process cannot access the file '/home/vsts/work/1/s/build/tests/Release/net7.0/(project file).pdb' because it is being used by another process. [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): error : at Microsoft.Win32.SafeHandles.SafeFileHandle.Init(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Int64& fileLength, UnixFileMode& filePermissions) [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): error : at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Func`4 createOpenException) [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): error : at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): error : at Coverlet.Core.Helpers.FileSystem.Copy(String sourceFileName, String destFileName, Boolean overwrite) in /
/src/coverlet.core/Helpers/FileSystem.cs:line 35 [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): error : at Coverlet.Core.Helpers.InstrumentationHelper.BackupOriginalModule(String module, String identifier) in //src/coverlet.core/Helpers/InstrumentationHelper.cs:line 227 [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): error : at Coverlet.Core.Coverage.PrepareModules() in /
/src/coverlet.core/Coverage.cs:line 130 [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]
/home/vsts/work/1/.nuget/packages/coverlet.msbuild/3.2.0/build/coverlet.msbuild.targets(39,5): error : at Coverlet.MSbuild.Tasks.InstrumentationTask.Execute() in /_/src/coverlet.msbuild.tasks/InstrumentationTask.cs:line 116 [/home/vsts/work/1/s/tests/dotnet/(project file).csproj]

The Test phase eventually fails with error:
The active test run was aborted. Reason: Test host process crashed
Test Run Aborted with error System.Exception: One or more errors occurred.
---> System.Exception: Unable to read beyond the end of the stream.
at System.IO.BinaryReader.Read7BitEncodedInt()
at System.IO.BinaryReader.ReadString()
at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.LengthPrefixCommunicationChannel.NotifyDataAvailable()
at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TcpClientExtensions.MessageLoopAsync(TcpClient client, ICommunicationChannel channel, Action`1 errorHandler, CancellationToken cancellationToken)
--- End of inner exception stack trace ---.

I am aware of some other open issues related to coverlet since .NET 7 RC 1 (#1391, microsoft/vstest#4014) - Is this a known issue as well, or is anyone else running into this? I am struggling to find any documentation on it

@mfisher214
Copy link
Author

As an update, we had OutputPath tags in the csproj for all of our test projects that were outputting all test projects to the same directory. If we remove those tags from the test projects and allow them to be outputted to separate directories, then "Unable to instrument module" goes away and the build passed.

I suppose I will leave this open as outputting to one directory previously worked, in case anyone has any ideas/comments

@TFTomSun
Copy link
Contributor

TFTomSun commented Nov 15, 2022

we run into the same issue. We restore test packages from binaries using a temp project. All binaries get copied into one output.
Additionally to the stack trace above I also see a StackOverflowException with this partial stack trace:
Stack overflow.
at Mono.Cecil.Metadata.RowEqualityComparer.GetHashCode(Mono.Cecil.Metadata.Row2<System.String,System.String>) at System.Collections.Generic.Dictionary2[[Mono.Cecil.Metadata.Row2[[System.__Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], Mono.Cecil, Version=0.11.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e],[System.__Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].FindValue(Mono.Cecil.Metadata.Row2<System.__Canon,System.__Canon>)
at System.Collections.Generic.Dictionary2[[Mono.Cecil.Metadata.Row2[[System.__Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], Mono.Cecil, Version=0.11.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e],[System.__Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryGetValue(Mono.Cecil.Metadata.Row`2<System.__Canon,System.__Canon>, System.__Canon ByRef)
at Mono.Cecil.TypeDefinitionCollection.GetType(System.String, System.String)
at Mono.Cecil.ModuleDefinition.GetType(System.String, System.String)
at Mono.Cecil.MetadataResolver.GetTypeDefinition(Mono.Cecil.ModuleDefinition, Mono.Cecil.TypeReference)
at Mono.Cecil.MetadataResolver.GetType(Mono.Cecil.ModuleDefinition, Mono.Cecil.TypeReference)
at Mono.Cecil.MetadataResolver.Resolve(Mono.Cecil.TypeReference)
at Mono.Cecil.ModuleDefinition.Resolve(Mono.Cecil.TypeReference)
at Mono.Cecil.ExportedType.Resolve()
at Mono.Cecil.MetadataResolver.GetType(Mono.Cecil.ModuleDefinition, Mono.Cecil.TypeReference)
at Mono.Cecil.MetadataResolver.Resolve(Mono.Cecil.TypeReference)
at Mono.Cecil.ModuleDefinition.Resolve(Mono.Cecil.TypeReference)
at Mono.Cecil.ExportedType.Resolve()
at Mono.Cecil.MetadataResolver.GetType(Mono.Cecil.ModuleDefinition, Mono.Cecil.TypeReference)
at Mono.Cecil.MetadataResolver.Resolve(Mono.Cecil.TypeReference)
at Mono.Cecil.ModuleDefinition.Resolve(Mono.Cecil.TypeReference)
at Mono.Cecil.ExportedType.Resolve()
at Mono.Cecil.MetadataResolver.GetType(Mono.Cecil.ModuleDefinition, Mono.Cecil.TypeReference)
at Mono.Cecil.MetadataResolver.Resolve(Mono.Cecil.TypeReference)
at Mono.Cecil.ModuleDefinition.Resolve(Mono.Cecil.TypeReference)
at Mono.Cecil.ExportedType.Resolve()
at Mono.Cecil.MetadataResolver.GetType(Mono.Cecil.ModuleDefinition, Mono.Cecil.TypeReference)
at Mono.Cecil.MetadataResolver.Resolve(Mono.Cecil.TypeReference)
at Mono.Cecil.ModuleDefinition.Resolve(Mono.Cecil.TypeReference)
at Mono.Cecil.ExportedType.Resolve()
at Mono.Cecil.MetadataResolver.GetType(Mono.Cecil.ModuleDefinition, Mono.Cecil.TypeReference)
at Mono.Cecil.MetadataResolver.Resolve(Mono.Cecil.TypeReference)
at Mono.Cecil.ModuleDefinition.Resolve(Mono.Cecil.TypeReference)

@ricardo-noyolalozano
Copy link

I'm seeing this same issue but in net 6.0

@daveMueller
Copy link
Collaborator

@mfisher214 sorry for the late response. I'm not aware of any other issues related to .NET 7 than the one you already mentioned. Would it be possible that someone could provide a simple repro for that?

@daveMueller daveMueller added the waiting for customer Waiting for customer action label Apr 10, 2023
@github-actions
Copy link

github-actions bot commented Sep 3, 2023

This issue is stale because it has been open for 3 months with no activity.

@github-actions github-actions bot added the stale label Sep 3, 2023
@Bertk
Copy link
Collaborator

Bertk commented Feb 7, 2024

issue is meanwhile outdated. coverlet tests are targeting net6.0 and net8.0 with PR #1544

@Bertk Bertk added Solved The issue is solved and can be closed and removed waiting for customer Waiting for customer action stale labels Feb 7, 2024
@Bertk
Copy link
Collaborator

Bertk commented Feb 20, 2024

coverlet V6.0.1 is released.

@Bertk Bertk closed this as completed Feb 20, 2024
@YoshiRulz
Copy link

YoshiRulz commented Nov 2, 2024

I'm seeing the same infinite recursion in Cecil.
Deps: these + <PackageVersion Include="coverlet.msbuild" Version="6.0.2" />.
SDK: 8.0.300 from Nixpkgs.
Mono: 6.12.0.182 from Nixpkgs, though I don't think that's relevant because the same error appears if I change the test project to target net8.0.

@Bertk Bertk added needs more info More details are needed needs repro Needs repro to be investigated, cannot repro in local and removed Solved The issue is solved and can be closed labels Nov 2, 2024
@Bertk
Copy link
Collaborator

Bertk commented Nov 3, 2024

@YoshiRulz Please provide more information e.g. diagnostic logs and steps to reproduce

dotnet test --no-build -bl:test.binlog /p:CollectCoverage=true /p:ExcludeByAttribute="GeneratedCodeAttribute" --diag:"BizHawk.diag.log;tracelevel=verbose"

Please also create a new issue. This one was closed.

@Bertk Bertk added the waiting for customer Waiting for customer action label Nov 3, 2024
@lydia-samuel-applied-systems

Hey as for the stack overflow issue, I believe this may be related to this ticket under cecil.

jbevain/cecil#806

@Bertk Bertk added tracking-external-issue The issue is caused by external problem - nothing we can do to fix it directly and removed waiting for customer Waiting for customer action needs repro Needs repro to be investigated, cannot repro in local labels Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info More details are needed tracking-external-issue The issue is caused by external problem - nothing we can do to fix it directly
Projects
None yet
Development

No branches or pull requests

7 participants