51CTO 部落格位址:https://blog.51cto.com/13969817
部落格園部落格位址: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(),如下圖所示: