繁体   English   中英

将[Microsoft.SharePoint.Client.ClientContext]强制转换为Powershell类方法会导致错误

[英]Casting [Microsoft.SharePoint.Client.ClientContext] to a Powershell Class Method results in an error

这是我的代码:

Class Tracker : WebObject {

$url
$username
$password

[Microsoft.SharePoint.Client.ClientContext] Context() {

    $context = New-Object Microsoft.SharePoint.Client.ClientContext($this.url)
    return $context
}

Tracker ([string]$url,[string]$username,[string]$password) {
    $this.url = $url
    $this.username = $username
    $this.password = $password
}

我在脚本顶部添加了require dll:

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"

但是,当我运行它时,出现以下错误:

Unable to find type [Microsoft.SharePoint.Client.ClientContext].

对出什么问题有任何想法吗?

我发现了这一点:您无法在使用类的脚本中导入dll。 解决方法是将二进制文件导入另一个脚本并通过点源包含类的脚本来加载类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM