FileLoadException: Could not load file or assembly

2020-06-20 23:49发布

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?

4条回答
一纸荒年 Trace。
2楼-- · 2020-06-21 00:33

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.

查看更多
干净又极端
3楼-- · 2020-06-21 00:42

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.

查看更多
劳资没心,怎么记你
4楼-- · 2020-06-21 00:46

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.

查看更多
一夜七次
5楼-- · 2020-06-21 00:53

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.

查看更多
登录 后发表回答