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

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.


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.