简体   繁体   English

依赖关系不匹配:解决方案不会使用4.0.0.0以上的版本

[英]Dependency Mismatch: Solution won't use anything newer than 4.0.0.0

When I try to run the solution, I'll get an error: Could not load file or assembly 'System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. 当我尝试运行解决方案时,会出现错误: Could not load file or assembly 'System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Could not load file or assembly 'System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

System.Net.Http version 4.0.0 is always in use. 始终使用System.Net.Http版本4.0.0。 I have tried to update, downgrade and god knows what for hours now. 我试图进行更新,降级,而上帝已经知道了几个小时了。 Nothing I've tried works. 我没有尝试过任何工作。

This is my project.json: 这是我的project.json:

{
  "dependencies": {
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.2",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.2",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.2",
    "Microsoft.Extensions.Configuration.Json": "1.1.2",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.1.2",
    "Microsoft.Extensions.Logging": "1.1.2",
    "Microsoft.Extensions.Logging.Console": "1.1.2",
    "Microsoft.Extensions.Logging.Debug": "1.1.2",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.2",
    "Microsoft.ServiceFabric": "5.6.220",
    "Microsoft.ServiceFabric.AspNetCore.WebListener": "2.6.220",
    "Microsoft.ServiceFabric.Data": "2.6.220",
    "Microsoft.ServiceFabric.Services": "2.6.220",
    "Microsoft.AspNetCore.Mvc.Formatters.Xml": "1.0.1",
    "Microsoft.AspNetCore.Authentication.Cookies": "1.1.1",
    "microsoft.aspnetcore.authentication.jwtbearer": "1.1.1",
    "System.Net.Http": "4.3.2"
  },

  "tools": {
  },

  "frameworks": {
    "net461": {}

  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
  }
}

In there I have written "System.Net.Http": "4.3.2" , but as you can see in this image, the reference version is 4.0.0: 在这里,我编写了"System.Net.Http": "4.3.2"但是正如您在此图中看到的,参考版本是4.0.0:

What am I doing wrong and how can I fix it? 我在做什么错,我该如何解决? I'm getting a bit confused. 我有点困惑。 I declare 4.3.2, the reference is 4.0.0 and the error says 4.1.1? 我声明4.3.2,引用为4.0.0,错误为4.1.1? I have searched everywhere for version 4.1.1, but didn't find anything. 我到处都搜索了4.1.1版,但没有找到任何东西。

Edit: I'm using VS 2015 on a windows 7 machine. 编辑:我在Windows 7计算机上使用VS 2015。

I have also tried to redirect to the correct assembly version in the config json file with no success. 我也尝试过重定向到config json文件中的正确程序集版本,但没有成功。

For whatever reason VS 2015 would fallback to v4.0.0 of System.Net.Http if multiple package versions were used. 无论出于何种原因,如果使用多个软件包版本,VS 2015都将回退到System.Net.Http v4.0.0。 What you could do is: 您可以做的是:

  1. Upgrade your .NET Core projects to v1.1 and use VS 2017. .NET Core项目升级到v1.1并使用VS 2017。
  2. Remove Microsoft.AspNetCore.Authentication.JwtBearer which has a dependency on System.Net.Http v4.0.0. 删除Microsoft.AspNetCore.Authentication.JwtBearer这对依赖System.Net.Http V4.0.0。

依存关系

If Microsoft.AspNetCore.Authentication.JwtBearer is needed in your project, then #1 might be the only option. 如果您的项目中需要Microsoft.AspNetCore.Authentication.JwtBearer ,则#1可能是唯一的选择。

Reference the latest version of System.Net.Http and add to your app.config bindingRedirect like that: 引用最新版本的System.Net.Http并添加到您的app.config bindingRedirect中,如下所示:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.1.0" />
       </dependentAssembly>
       <!-- Other possible redirects... -->
    </assemblyBinding>
 </runtime>

Please adjust the version and other values in my redirect if needed. 如果需要,请在重定向中调整版本和其他值。

At least that's how it worked before, may be in .Net Core something changed, in that case, you at least have an idea of what to do now. 至少以前是这样的,在.Net Core中可能有所更改,在这种情况下,您至少对现在应该做什么有一个了解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有Object参数的方法将不接受Object以外的任何东西 - Method with Object argument won't accept anything other than an Object 数组不会输出任何东西 - Array won't output anything Visual Studio 2017将不会在堆栈跟踪中显示任何内容,并且会压碎我的应用程序 - Visual Studio 2017 won't show anything in stack trace and than crushes my application 初始化线程不会打印任何内容 - Initialize thread won't print anything C ++ CLI DLL不由IIS7加载,但仅在使用比VS2008更新的版本构建时才加载 - C++ CLI DLL not being loaded by IIS7 but only if built with anything newer than VS2008 依赖注入容器:如何处理不依赖于任何东西的对象? - Dependency injection containers: how to handle objects that aren't a dependency of anything? Visual Studio解决方案资源管理器不允许我使用/查看新的.xaml文件 - Visual Studio Solution Explorer won't let me use / see new .xaml files 数据类型不匹配不会让我保存到数据库 - Data type mismatch won't let me save to database 由于目标框架不匹配,Nuget 不会安装 package - Nuget won't install package, due to a mismatch in the targeted framework 如何在依赖属性中获取/设置什么都不做? - Howcome the get/set in dependency property doesn't do anything?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM