【问题标题】:Cannot load Microsoft.SharePoint.Client.dll in powershell script无法在 powershell 脚本中加载 Microsoft.SharePoint.Client.dll
【发布时间】:2016-05-06 09:06:04
【问题描述】:

我正在尝试使用 powershell 脚本连接到 offce365 共享点站点。但是,我尝试加载共享点程序集的所有命令都不起作用。

错误信息(抱歉,是德语)如下所示:

Add-Type : Die Datei oder Assembly "file:///'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" oder eine Abhängigkeit davon wurde nicht gefunden. Die Assembly wird von einer Laufzeit erstellt, die aktueller als die derzeit geladene Laufzeit ist, und kann nicht geladen werden.
Bei C:\Users\****\Desktop\onfb\odfb.ps1:6 Zeichen:9
+ Add-Type <<<<  -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'
    + CategoryInfo          : NotSpecified: (:) [Add-Type], BadImageFormatException
    + FullyQualifiedErrorId : System.BadImageFormatException,Microsoft.PowerShell.Commands.AddTypeCommand

它说,组件(或依赖项)要么找不到,要么是由比我正在使用的版本更新的版本创建的。

首先我尝试使用

加载初始文件
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'

之后我尝试了以下命令:

Add-Type -Path ([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client").location)

我还尝试将文件复制到另一个文件夹,并相应地更改了引用。

我也设置了

<runtime>
    <loadfromremotesources enabled="true"/>
</runtime>

在 powershell.exe.config 文件中。哪个不存在,所以我创建了它。

我正在提升模式下运行 powershell,并且还尝试了不受限制的安全性。

有人知道怎么解决吗?

谢谢!

【问题讨论】:

    标签: powershell sharepoint office365


    【解决方案1】:

    准确的英文错误信息是:

    此程序集由比当前加载的运行时更新的运行时构建 运行时,无法加载。

    很可能发生这种情况,因为您使用的是 PowerShell 版本 2,但 SharePoint Online Client Components SDK 的目标是 .Net Framework v4.0

    如何确定已安装的 PowerShell 版本:

    PS C:\> $PSVersionTable.PSVersion
    

    .NET 4 CLR 可以加载 .NET 2 程序集,但反之则不行。所以,你必须升级 PowerShell。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-21
      • 2021-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-27
      • 1970-01-01
      相关资源
      最近更新 更多