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

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

问题描述

我有一个在完整的.net Framework 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。运行时,
版本= 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] 平台,部署到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:

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

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天全站免登陆