Cannot load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=3.1.0.0' in MSTest project

百般思念 提交于 2021-01-29 02:08:57

问题


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);
        }
    }
}

回答1:


Resolved by enabling auto binding redirection

<PropertyGroup>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>



回答2:


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.



来源:https://stackoverflow.com/questions/61449325/cannot-load-file-or-assembly-microsoft-extensions-configuration-abstractions-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!