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

5

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?

.net
asp.net-core
.net-core
asked on Stack Overflow Aug 26, 2017 by SÅ‚awomir Rosiek • edited Aug 27, 2017 by SÅ‚awomir Rosiek

4 Answers

13

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.

answered on Stack Overflow Aug 27, 2017 by mcolhoun
6

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.

answered on Stack Overflow Nov 9, 2018 by Alex Stephens
0

Although this is an old post, I ran into the same problem where I build a site using .NET 4.7.2, and everything worked OK on my machine, once uploaded to the client-server I got the following error:

Could not load all types from "Umbraco.Web, Version=8.0.0.0 System.Net.Http, Version=4.2.0.0

After a bit of head scratching and communication with the client, they allowed me access to their server which was Windows 2016.

Their server did not have 4.7.2 installed, so once downloaded and installed the problem was fixed.

Although this post has a lot of comments https://github.com/dotnet/corefx/issues/22781 if possible I would recommend checking to see if the server has the same .NET framework that you are targeting.

answered on Stack Overflow Jun 14, 2019 by George Phillipson
0

I had the same issue. I emptied the bin folder on my local machine and performed Build operation again, then copied the new bin folder to the server and it started working.

answered on Stack Overflow May 14, 2020 by Jaideep Dhumal

User contributions licensed under CC BY-SA 3.0