FileLoadException:无法加载文件或程序集 System.Runtime,版本 = 4.2.0.0 [英] FileLoadException: Could not load file or assembly System.Runtime, Version=4.2.0.0

查看:57
本文介绍了FileLoadException:无法加载文件或程序集 System.Runtime,版本 = 4.2.0.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在完整的 .net 框架 4.6.1 上运行的 asp.net core 2.0 应用程序.它在本地工作正常,但是当我将它部署到 Azure 时,我收到以下错误:

I have an asp.net core 2.0 application that runs on full .net framework 4.6.1. It works fine locally but when I deploy it to Azure I receive the following error:

FileLoadException: 无法加载文件或程序集System.Runtime,版本=4.2.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3a' 或它的依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT 的例外:0x80131040)

FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

在 Debug/Release 文件夹中,我有 System.Runtime 4.1.2.0 但不知何故它可以工作.

In Debug/Release folder I have System.Runtime 4.1.2.0 but somehow it works.

在经典".NET 框架中,我曾经将程序集重定向添加到 app.config,但在这里我没有 web.config.知道如何解决这个问题吗?

In "classic" .NET framework I used to add assembly redirect to app.config but here I don't have web.config. Any idea how to fix that?

推荐答案

如果您创建面向 [.NET Core] 平台的 ASP.NET Core 2.0 Web 应用程序,部署到Azure(或在本地部署),然后将其更改为以 [.NET Framework] 为目标.

This can happen if you create an ASP.NET Core 2.0 Web Application that targets the [.NET Core] platform, deploy to Azure (or deploy locally), and then change it to target the [.NET Framework] instead.

例如如果你改变

<PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
    <TargetFramework>net461</TargetFramework>
</PropertyGroup>

但如果您在重新部署之前不从 Azure 中删除现有文件,您将收到此错误.

but if you do not delete the existing files from Azure before redeploying you will get this error.

它也可能发生在以下场景中:

It can also happen in the following scenario:

  • 首先使用 Visual Studio 2017 创建一个 .NET Core 项目:

  • First create a .NET Core project with Visual Studio 2017 with:

文件 -> 新建项目 -> Visual C# > Web > Asp.NET Core 应用程序`

File -> New Project -> Visual C# > Web > Asp.NET Core Application`

在第二个屏幕上选择 [.NET Core] 平台.

Choose the [.NET Core] Platform on the Second Screen.

  • 将 Web 应用部署到 Azure.
  • 然后创建一个新项目:

  • Deploy the web app to Azure.
  • Then create a new Project with :

文件 -> 新建项目 -> Visual C# > Web > Asp.NET Core 应用程序`

File -> New Project -> Visual C# > Web > Asp.NET Core Application`

在第二个屏幕上选择 .NET Framework 设置.

Choose the .NET Framework setting on the Second Screen.

重新部署而不删除 Azure 中的现有文件会导致此错误.

Redeploy without deleting the existing files from Azure will cause this error.

希望有所帮助.

这篇关于FileLoadException:无法加载文件或程序集 System.Runtime,版本 = 4.2.0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆