[英]Casting [Microsoft.SharePoint.Client.ClientContext] to a Powershell Class Method results in an error
Here is my code: 这是我的代码:
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
}
I have added the require dlls at the top of the script: 我在脚本顶部添加了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"
However, when I run it I receive the following error: 但是,当我运行它时,出现以下错误:
Unable to find type [Microsoft.SharePoint.Client.ClientContext].
Any thoughts on what's going wrong? 对出什么问题有任何想法吗?
I figured this out: you can't import dlls in a script that uses classes. 我发现了这一点:您无法在使用类的脚本中导入dll。 the workaround is to import the binaries in another script and load the classes in by dot sourcing the script containing the classes. 解决方法是将二进制文件导入另一个脚本并通过点源包含类的脚本来加载类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.