Skip to content

NUnit 4.2.0 is missing System.Buffers on .NET Framework #4795

@ghelyar

Description

@ghelyar

Upgrading from NUnit 4.1.0 to 4.2.0 in a .NET Framework project causes a System.IO.FileNotFoundException of System.Buffers at runtime, when asserting equality on any type after the StreamsComparer in the list, including enums, chars, etc.

It looks like it's because while it goes through the comparers it's trying to use a StreamsComparer, which was changed to use System.Buffers here, but this probably needs a package reference for .NET Framework.

In fact at the time that had

#if !NETFRAMEWORK
using System.Buffers;
#endif

but that got removed here.

Error:

System.IO.FileNotFoundException : Could not load file or assembly 'System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
   at NUnit.Framework.Constraints.Comparers.StreamsComparer.Equal(Object x, Object y, Tolerance& tolerance, ComparisonState state, NUnitEqualityComparer equalityComparer)
   at NUnit.Framework.Constraints.NUnitEqualityComparer.AreEqual(Object x, Object y, Tolerance& tolerance, ComparisonState state)
   at NUnit.Framework.Constraints.NUnitEqualityComparer.AreEqual(Object x, Object y, Tolerance& tolerance)
   at NUnit.Framework.Constraints.EqualConstraint.ApplyTo[TActual](TActual actual)
   at NUnit.Framework.Assert.That[TActual](TActual actual, IResolveConstraint expression, NUnitString message, String actualExpression, String constraintExpression)
   at nurepro.Repro.Test()

Repro:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net48</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
    <PackageReference Include="NUnit" Version="4.2.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="4.6.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>
using NUnit.Framework;

namespace nurepro
{
    public class Repro
    {
        [Test]
        public void TestEnum()
        {
            Assert.That(Foo.Bar, Is.EqualTo(Foo.Bar));
        }
        
        [Test]
        public void TestChar()
        {        
            Assert.That('x', Is.EqualTo('x'));
        }
    }

    public enum Foo
    {
        Bar = 1,
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    is:bugpri:criticalUse this to indicate a hotfix may be necessary

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions