51CTO博客地址:https://blog.51cto.com/1396817
博客園博客地址:https://www.cnblogs.com/bxapollo
今天有遇到調用Microsoft.SharePoint.Client.dll的方法獲取數據,在執行PowerShell加載SharePoint Online Assemblies時出現異常,執行PowerShell命令如下:
- 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"
錯誤異常如下圖所示:

排錯:查看了對應目錄發現該dll文件是存在的,那麼為什麼會出現異常呢?

解決方案:在查找大量資料後,發現可能是.net 4.0的一個bug,默認的情況下禁用從遠程位置加載的程序集中執行代碼的功能,所以可以使用如下方法解決問題:
[System.Reflection.Assembly]::LoadFrom(),

相關資料連接:Assembly.LoadFrom方法
總結該問題的解決方案,希望能對其他有問題的小夥伴帶來幫助,謝謝閲讀。