Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileLoadException: Could not load file or assembly System.Runtime, Version=4.2.0.0

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: 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)

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

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?

like image 364
Sławomir Rosiek Avatar asked Aug 26 '17 11:08

Sławomir Rosiek


2 Answers

What worked for me was:

Simply, empty the bin folder in your project and rebuild. I had to manually delete the contents via windows explorer as 'clean' left files kicking around.

Job done.

like image 105
Alex Stephens Avatar answered Oct 20 '22 18:10

Alex Stephens


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.

e.g. if you change

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

to

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

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:

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

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

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

targeting .NET Core Platform

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

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

  • Choose the .NET Framework setting on the Second Screen.

targeting the .NET Framework

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

Hope that helps.

like image 41
mcolhoun Avatar answered Oct 20 '22 18:10

mcolhoun