51CTO blog address: https://blog.51cto.com/13969817blog
garden blog address: https://www.cnblogs.com/bxapollo
Today, I encountered the method of calling Microsoft.SharePoint.Client.dll to obtain data. An exception occurred when executing Powershell to load SharePoint Online Assemblies. The following Powershell commands were executed:
- Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
- Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
The error exception is shown in the figure below:
Troubleshooting: I checked the corresponding directory and found that the dll file exists, so why is there an exception?
Solution: After searching a lot of information, I found that this may be a bug in .net 4.0. By default, the function of executing code in assemblies loaded from remote locations is disabled, so the following methods can be used to solve the problem: [System.Reflection .Assembly]::LoadFrom(), as shown in the figure below:
Related information link:
Summarize the solution to this problem, hoping to help other friends who have problems, thank you for reading.