Skip to content

Approval methods fail with TypeInitializationException under .NET 5 #717

@slang25

Description

@slang25

As found by @gkinsman, when using things like .ShouldMatchApproved() results in an exception being thrown when targetting net5:

System.TypeInitializationException : The type initializer for 'EmptyFiles.AllFiles' threw an exception.

Repo: https://github.com/gkinsman/ShouldlyRepro

This is because the EmptyFiles package is expected to copy an EmptyFile directory to the bin folder on build, and does this via targets files in the nuget package.

Something has changed in .NET 5 around the behavior of transitive dependencies here, if we explicitly reference EmptyFile as a top-level dependency then it works. That would be a quick workaround for Shouldly users.

I'm just creating a PR in EmptyFiles which I think will handle .NET5 appropriately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions