Skip to content

[BUG] TypeInitializationException when targeting .NET Framework #1818

Closed

Description

@martincostello

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:

  • Which coverlet package (collector, console, msbuild, ...) and version was used? coverlet.msbuild@8.0.0
  • Which version of .NET is the code running on? net481
  • What OS and version, and what distro if applicable? Windows 10
  • What is the architecture (x64, x86, ARM, ARM64)? x64
  • Do you know whether it is specific to that configuration? Yes

Additional context

None.

Activity

  1. jaredpar commented on Feb 16, 2026

    @jaredpar

    Seeing the same in my projects jaredpar/complog#329

  2. Bertk commented on Feb 17, 2026

    @Bertk
    Collaborator

    Thank you for the feedback. We’ll update the README.md to include the required .NET 8.0 runtime for the test environment. Other target framework versions can still be used for the test projects.

  3. added
    bug
    skip-changelog
    and removed
    untriaged
    on Feb 17, 2026
  4. martincostello commented on Feb 17, 2026

    @martincostello
    ContributorAuthor

    So if I'm understanding correctly, .NET Framework support has been completely dropped and we have to find a completely different code coverage solution now?

  5. Bertk commented on Feb 17, 2026

    @Bertk
    Collaborator
  6. martincostello commented on Feb 17, 2026

    @martincostello
    ContributorAuthor

    OK, so I'm confused then.

    You reply makes it sound like a docs issue regarding the minimum supported version, not a bug, but my test project multi-targets with net10.0 and net481.

    I don't see how that doesn't meet the minimum runtime requirement?

    netfx support just seems broken in 8.0.0.

  7. Bertk commented on Feb 17, 2026

    @Bertk
    Collaborator

    Kindly install the .NET 8.0 SDK on your test system and execute the tests without changing the target framework. Coverlet depends on the .NET 8.0 base class libraries to run successfully.

  8. martincostello commented on Feb 17, 2026

    @martincostello
    ContributorAuthor

    So it needs exactly .NET 8, and doesn't work if only .NET 9 or 10 installed? That's particularly confusing for .NET Framework support and when it works fine with only the .NET 10 SDK installed on Linux and macOS.

    If that's the case, that's a bug IMHO as it should work with all currently supported versions of .NET.

  9. jaredpar commented on Feb 17, 2026

    @jaredpar

    Can you elaborate a bit on why the .NET 8 SDK is required for .NET Framework testing. Do you all do some kind of shell out to another process here? Or use tools from the .NET 8 SDK?

  10. Bertk commented on Feb 18, 2026

    @Bertk
    Collaborator

    The requirement for the .NET 8 SDK comes from the fact that coverlet.msbuild v8.0.0 depends on several Microsoft.Extensions.* packages version 8.0.0.x (which are part of .NET 8 LTS). These dependencies are internal and not directly exposed, which is why the SDK requirement may not be immediately obvious.

    Coverlet v8.0.0 is also the first version to support multiple target frameworks. At the moment, coverlet.msbuild targets net8.0 and netstandard2.0. These represent the minimum supported .NET runtime frameworks for execution.

    To answer your question more directly:
    There is no special “shelling out” behavior involved. The dependency on the .NET 8 SDK is driven by the underlying package and runtime requirements rather than invoking separate external tools from the SDK.

    Image

    Additionally, a new package — coverlet.MTP — will be released soon once some deployment issues are resolved. This will be a Microsoft Testing Platform extension and is planned to support newer runtimes, including .NET 10.
    (see https://github.com/Bertk/coverlet-examples)

    I hope this helps clarify things, and please feel free to ask if you’d like more details.

    Image
  11. 45 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Solvedbugdocumentationskip-changelog

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions