问题
I am suddenly seeing this error when running my app (published on Azure app service:
Could not load file or assembly 'Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified. at SharePointLibrary.SPClient.GetAllUsers() at ADVWKSP.Managers.UserManager.GetUsers() in C:\Users\bassie\source\repos\TFS\ADVWKSP\ADVWKSP\Managers\UserManager.cs:line 21
It runs fine on my machine, and it used to run fine after publish but now it just suddenly starts crying about this file missing.
I checked in Kudu and I can only see the SharePoint.Client.Runtime
:
Why? How can I ensure that all required libraries are published with the project. Why did this suddenly stop working?
回答1:
The hosting environment of azure web app contains a standard installation of .Net framework 2.0
to .Net framework 4.5
.
If your application referenced assemblies which is not build in .Net framework, you have to "include" them with your deploy package. Even these are Microsoft assemblies.
Setting the Copy Local property to True for the referenced assembly may fix it.
1.In Solution Explorer find your project's reference to the library.
2.Right click and choose Properties.
3.In the Properties window set Copy Local to True.
As you said, it works locally on IIS Express, please try to deploy your website content manually to Azure via KUDU or FTP client and find out whether it works or not.
回答2:
Adding the following parameter
/deployonbuild=false
to the msbuild command line fixed the issue.
来源:https://stackoverflow.com/questions/50615813/could-not-load-file-or-assembly-after-publishing-to-azure-app-service