[BUG] TypeInitializationException when targeting .NET Framework (original) (raw)

Describe the bug

When targeting net481 with coverlet.msbuild@8.0.0, a TypeInitializationException is thrown when tests are run.

To Reproduce

  1. Clone martincostello/sqllocaldb@369c323 on a Windows machine
  2. Run build.ps1 from the root of the repository.

Expected behavior

Tests pass and coverage is collected.

Actual behavior

Error: System.TypeInitializationException : The type initializer for 'Coverlet.Core.Instrumentation.Tracker.MartinCostello.SqlLocalDb_d1a4020d-c271-494f-94d5-55a151367e7c' threw an exception.
---- System.IO.FileNotFoundException : Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

  Failed MartinCostello.SqlLocalDb.Interop.WindowsRegistryTests.OpenSubKey_Returns_Null_If_Key_Not_Found [152 ms]
  Error Message:
   System.TypeInitializationException : The type initializer for 'Coverlet.Core.Instrumentation.Tracker.MartinCostello.SqlLocalDb_d1a4020d-c271-494f-94d5-55a151367e7c' threw an exception.
---- System.IO.FileNotFoundException : Could not load file or assembly 'System.Runtime, Version=8.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.MartinCostello.SqlLocalDb_d1a4020d-c271-494f-94d5-55a151367e7c.RecordHit(Int32 )
   at MartinCostello.SqlLocalDb.Interop.WindowsRegistry.OpenSubKey(String keyName) in /_/src/SqlLocalDb/Interop/WindowsRegistry.cs:line 18
   at MartinCostello.SqlLocalDb.Interop.WindowsRegistryTests.OpenSubKey_Returns_Null_If_Key_Not_Found() in /_/tests/SqlLocalDb.Tests/Interop/WindowsRegistryTests.cs:line 18
----- Inner Stack Trace -----
   at Coverlet.Core.Instrumentation.Tracker.MartinCostello.SqlLocalDb_d1a4020d-c271-494f-94d5-55a151367e7c..cctor()

Configuration (please complete the following information):

Please provide more information on your .NET configuration:

Additional context

None.