I'm having problem with MSTest, Here the issue

  • Open VS2019
  • Make sure that package management is set to [PackageReference]
  • Create a .Net Framework test project
  • Add Nuget package Microsoft.Extentions.Configuration last version (3.1.3.0)
  • Add the code below
  • Run test
  • ==> Test fail with error [Cannot load file or assembly Microsoft.Extensions.Configuration.Abstractions, Version=3.1.0.0 ...] error

PS : using package.config instead of PackageReference solve the issue. Downgrading to Microsoft.Extentions.Configuration to 3.1.0.0 fixes the issue too

What's the problem here ?

Thanks

using Microsoft.Extensions.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace TestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            var configuration = new ConfigurationBuilder().Build();
            Assert.IsNotNull(configuration);
        }
    }
}
2

There are 2 best solutions below

0
On BEST ANSWER

Resolved by enabling auto binding redirection

<PropertyGroup>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
0
On

Even though I fixed my problem, it's not clear for me why it's requesting version 3.1.0.0 when I added version 3.1.3.0. I looked at package dependencies, and i didn't find any other package referencing a lower version. If some one has an idea or a simple thought just drop an answer here.

Thanks.