【问题标题】:Baffling conflict with multiple nuget packages: System.MissingMethodException : Method not found: 'Microsoft.Extensions.Primitives.IChangeToken'与多个 nuget 包的莫名冲突:System.MissingMethodException:找不到方法:'Microsoft.Extensions.Primitives.IChangeToken'
【发布时间】:2021-12-09 12:56:28
【问题描述】:

我遇到了多个对我没有意义的 nuget 包之间的非常奇怪的冲突,我一直在努力解决它。我会提供赏金,因为我已经花了几天时间。完整的错误:

System.MissingMethodException:找不到方法:'Microsoft.Extensions.Primitives.IChangeToken Microsoft.Extensions.Configuration.IConfiguration.GetReloadToken()'。

我同时使用了两个不同的 nuget 包:Any-Config(配置库)和NUnit.Extensions.TestMonitor(用于实时测试监控的 nunit 扩展),它们彼此无关。 Any-Config 具有 IConfiguration 的完整实现。一切都可以自己正常工作,但是当我尝试在引用SignalR 并在项目中使用<FrameworkReference Include="Microsoft.AspNetCore.App" /> 的FrameworkReference 的net5 项目中使用它们时,会引发此错误,令人费解的是如何发生这种情况。我怀疑一些框架巫术,但我现在真的不知道。

如果我删除 SignalR nuget 包 - 或 - FrameworkReference 一切正常。这是完整的复制项目:

UnitTest1.cs:

public class Tests
{
    [Test]
    public void Test1()
    {
        var value = AnyConfig.Config.Get<bool>("TestBool");
        Assert.AreEqual(true, value);
    }
}

appsettings.json:

{
  "TestBool": true
}

TestProject.csproj:

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

    <PropertyGroup>
        <TargetFramework>net5.0</TargetFramework>
        <IsPackable>false</IsPackable>
    </PropertyGroup>

    <ItemGroup>
        <FrameworkReference Include="Microsoft.AspNetCore.App" />
    </ItemGroup>

    <ItemGroup>
        <!-- comment out SignalR package and everything works -->
        <PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="5.0.11" />
        <!-- -->

        <PackageReference Include="Any-Config" Version="1.0.155" />
        <PackageReference Include="NUnit.Extension.TestMonitor" Version="1.0.51" />
        <PackageReference Include="NUnit" Version="3.12.0" />
        <PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
    </ItemGroup>

    <ItemGroup>
        <None Update="appsettings.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
    </ItemGroup>

</Project>

我不确定这些场景中的任何一个如何在调用时突然使实现消失 - 纯粹是通过引用包。如果我尝试在调试器中单步执行 Any-Config,它会在代码中的意外位置中断,并且调试器似乎很困惑。

【问题讨论】:

    标签: .net-core nunit signalr.client asp.net-core-signalr any-config


    【解决方案1】:

    经过将近一周的心痛后,我能够解决这个问题 - NUnit.Extension.TestMonitor 包引用了导致问题的 NUnit.Engine 3.12。如果降级到 NUnit.Engine 3.11,它可以正常工作,所以我必须向他们报告这个问题,看看有什么变化可能导致这个非常奇怪的问题!

    更新了仅使用 NUnit.Engine 触发问题的重现源:

    UnitTest1.cs:

    public class Tests
    {
        [Test]
        public void Test1()
        {
            var value = AnyConfig.Config.Get<bool>("TestBool");
            Assert.AreEqual(true, value);
        }
    }
    

    appsettings.json:

    {
      "TestBool": true
    }
    

    TestProject.csproj:

    <Project Sdk="Microsoft.NET.Sdk">
    
        <PropertyGroup>
            <TargetFramework>net5.0</TargetFramework>
            <IsPackable>false</IsPackable>
        </PropertyGroup>
    
        <ItemGroup>
            <FrameworkReference Include="Microsoft.AspNetCore.App" />
        </ItemGroup>
    
        <ItemGroup>
            <!-- comment out SignalR package and everything works -->
            <PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="5.0.11" />
            <!-- -->
    
            <PackageReference Include="Any-Config" Version="1.0.155" />
            <PackageReference Include="NUnit" Version="3.12.0" />
            <PackageReference Include="NUnit.Engine" Version="3.12.0" />
            <PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
            <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
        </ItemGroup>
    
        <ItemGroup>
            <None Update="appsettings.json">
                <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            </None>
        </ItemGroup>
    
    </Project>
    

    【讨论】:

      猜你喜欢
      • 2011-04-01
      • 2011-12-24
      • 2013-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-25
      • 2018-07-20
      相关资源
      最近更新 更多