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

[BUG] Type initializer errors after updating from 6.0.0 to 6.0.1 #1629

Closed
joaorosado opened this issue Feb 22, 2024 · 14 comments · Fixed by #1636
Closed

[BUG] Type initializer errors after updating from 6.0.0 to 6.0.1 #1629

joaorosado opened this issue Feb 22, 2024 · 14 comments · Fixed by #1636
Labels
bug Something isn't working with repro Issue with repro

Comments

@joaorosado
Copy link

Describe the bug
After upgrading from 6.0.0 to 6.0.1 the tests fail with errors initializing Coverlet

To Reproduce
Updated from 6.0.0 to 6.0.1.
Project being tested targets netstandard2.0. Only external reference is Newtonsoft.Json 13.0.3
Test project targets 4.7.2 and has the following references:

    <PackageReference Include="coverlet.msbuild" Version="6.0.1" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
    <PackageReference Include="GitVersion.MsBuild" Version="5.12.0" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
    <PackageReference Include="NSubstitute" Version="5.1.0" />
    <PackageReference Include="Nunit" Version="3.14.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
    <PackageReference Include="WireMock.Net" Version="1.5.40" />

Expected behavior
Tests to run without crashing

Actual behavior

   System.TypeInitializationException : The type initializer for 'Coverlet.Core.Instrumentation.Tracker.OutSystems.Auditing_cbebb53f-99cc-461e-8124-db81357fd8a1' threw an exception.
  ----> System.IO.FileNotFoundException : Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
  Stack Trace:
     at Coverlet.Core.Instrumentation.Tracker.OutSystems.Auditing_cbebb53f-99cc-461e-8124-db81357fd8a1.RecordHit(Int32 )
   at Auditing.Tests.AuditConfigTests.AuditConfigRequestTimeoutTest() in D:\a\1\s\tests\UnitTests\Auditing.Tests\AuditConfigTests.cs:line 12
--FileNotFoundException
   at Coverlet.Core.Instrumentation.Tracker.OutSystems.Auditing_cbebb53f-99cc-461e-8124-db81357fd8a1..cctor()

Configuration (please complete the following information):
Please provide more information on your .NET configuration:
* Which coverlet package and version was used? 6.0.1
* Which version of .NET is the code running on? 4.7.2
* What OS and version, and what distro if applicable? Windows 2022 (Azure CI agent windows-latest)
* What is the architecture (x64, x86, ARM, ARM64)?
* Do you know whether it is specific to that configuration? Don't know

Additional context
Current command being used to execute the tests:

dotnet test D:\a\1\s\tests\UnitTests\Auditing.Tests --configuration Release --no-restore --no-build --logger trx --framework net472 /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:ExcludeByFile=**/GitVersionInformation.* /p:CoverletOutput=D:\a\TestResults\coverage.net472.1.xml

Currently I'm not able to switch execution mode to the --collect version due to the test CI templates being shared by all our or organizational repositories. So cannot test with the --collect:"XPlat Code Coverage" option

@github-actions github-actions bot added the untriaged To be investigated label Feb 22, 2024
@joaorosado joaorosado changed the title [BUG] [BUG] Type initializer errors after updating from 6.0.0 to 6.0.1 Feb 22, 2024
@valadas
Copy link

valadas commented Feb 24, 2024

I got the same issue, interestingly the build worked fine on ubuntu github runner but failed on local builds/tests (on windows)

@santisq
Copy link

santisq commented Feb 25, 2024

@daveMueller
Copy link
Collaborator

Thanks a lot for reporting this. I can reproduce it with simply dotnet test /p:CollectCoverage=true. Repro is attached here.
Issue1629.zip

@daveMueller daveMueller added bug Something isn't working with repro Issue with repro and removed untriaged To be investigated labels Feb 25, 2024
@sungam3r
Copy link

The same here destructurama/attributed#109

@sungam3r
Copy link

@daveMueller
Copy link
Collaborator

I start working on this and see if I can figure something out.

@daveMueller
Copy link
Collaborator

So the problem only occurs for none-NetCore projects like in the bug description net472. As coverlet.core is now multitarget in version 6.0.1, msbuild is using the wrong assemblies.

image

I think the issue is here https://github.com/coverlet-coverage/coverlet/blob/master/src/coverlet.msbuild.tasks/coverlet.msbuild.props#L22-L23. We can't use the MSBuildRuntimeType for this condition as e.g. on my local this still is Core.

image

I see two options here. We could move back to build coverlet.core only targeting netstandard2.0. I already tried that out and it is working. Or try to work with some other condition.

cc: @MarcoRossignoli @Bertk

@MarcoRossignoli
Copy link
Collaborator

I see two options here. We could move back to build coverlet.core only targeting netstandard2.0. I already tried that out and it is working. Or try to work with some other condition.

I would go for now netstandard2.0 and we will work if needed to multi-tfm but with completely different packaging...like be fair and do not cheat nuget.

@daveMueller
Copy link
Collaborator

I think I would have found a condition that works but keeping it netstandard2.0 for now is fine for me. I'll create a PR.

@tmp64
Copy link

tmp64 commented Mar 7, 2024

I'm getting a similar error with net7.0-windows. It attempts to load System.Collections.Immutable, Version=8.0.0.0. There are no errors with coverlet.collector 6.0.0

Test log
> dotnet test --collect "XPlat Code Coverage"

Microsoft (R) Test Execution Command Line Tool Version 17.9.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.41]     REDACTED [FAIL]
[xUnit.net 00:00:00.42]     REDACTED [FAIL]
  Failed REDACTED [190 ms]
  Error Message:
   REDACTED
The type initializer for 'REDACTED' threw an exception.
---- System.TypeInitializationException : The type initializer for 'REDACTED' threw an exception.
-------- System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types.
Could not load file or assembly 'System.Collections.Immutable, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Could not find or load a specific file. (0x80131621)
Could not load file or assembly 'System.Collections.Immutable, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Could not find or load a specific file. (0x80131621)
  Stack Trace:
     at REDACTED.<>c__DisplayClass14_0.<REDACTED>g__REDACTED|1(<>c__DisplayClass14_1&) in REDACTED
   at REDACTED
----- Inner Stack Trace -----
   at REDACTED
----- Inner Stack Trace -----
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at REDACTED
  Failed REDACTED [< 1 ms]
Runtimes
Microsoft.AspNetCore.App 6.0.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
SDKs
7.0.304 [C:\Program Files\dotnet\sdk]
7.0.406 [C:\Program Files\dotnet\sdk]
8.0.201 [C:\Program Files\dotnet\sdk]

@daveMueller
Copy link
Collaborator

Hi guys, we finally merged everything we broke with the last release. We would really appreciate if someone could give it a try.
Here is how to consume the nightly: https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/ConsumeNightlyBuild.md

@sungam3r
Copy link

Fixed in destructurama/attributed#109

@daveMueller
Copy link
Collaborator

We now have a new official release 6.0.2 that can be consumed from nuget.org.

@sungam3r
Copy link

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working with repro Issue with repro
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants