[英]powershell bitstransfer object reference not set to an instance of an object
i have a program written in C# that uses powershell bitstransfer to upload and download a file from a machine.我有一个用 C# 编写的程序,它使用 powershell 位传输从机器上传和下载文件。 its been working fine until today when the upload and download stopped working giving this error.它一直工作正常,直到今天上传和下载停止工作并给出此错误。 It seems like the error is local to my machine because other machines work properly with bitstransfer and restarting the machine didn't fix the problem.似乎该错误是我机器的本地错误,因为其他机器可以正常使用 bitstransfer 并且重新启动机器并没有解决问题。 Could someone help me out?有人可以帮我吗? Thanks谢谢
PS Start-BitsTransfer -Source \\ip\data\filename.xml -Destination G:\\PLAYGROUND\\dir\\\
Start-BitsTransfer : Object reference not set to an instance of an object.
At line:1 char:19
+ Start-BitsTransfer <<<< -Source \\ip\data\filename.xml -Destination G:\\PLAYGROUND\\dir\\\
+ CategoryInfo : NotSpecified: (:) [Start-BitsTransfer], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Microsoft.BackgroundIntelligentTransfer.Management.NewBits
TransferCommand
PS Start-BitsTransfer -Source G:\\PLAYGROUND\\dir\\file.txt -Destination \\\\ip\\data\\\
Start-BitsTransfer : Object reference not set to an instance of an object.
At line:1 char:19
+ Start-BitsTransfer <<<< -Source G:\\PLAYGROUND\\dir\\file.txt -Destination \\\\ip\\data\\\
+ CategoryInfo : NotSpecified: (:) [Start-BitsTransfer], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Microsoft.BackgroundIntelligentTransfer.Management.NewBits
TransferCommand
我改用复制命令修复了它。
I think this happens when you have a high number of asynchronous jobs.我认为当您有大量异步作业时会发生这种情况。 All jobs in my case where either in failed or transferred state and after running Get-BitsTransfer | Remove-BitsTransfer
在我的情况下,处于失败或转移状态以及运行Get-BitsTransfer | Remove-BitsTransfer
后的所有作业Get-BitsTransfer | Remove-BitsTransfer
Get-BitsTransfer | Remove-BitsTransfer
I was able to start bits transfer. Get-BitsTransfer | Remove-BitsTransfer
我能够开始位传输。
I ran into this as well.我也遇到了这个。 If I added 60 transfers in quick succession I'd start getting errors.如果我快速连续添加 60 次传输,我会开始出错。 Here's how I handled it:以下是我的处理方式:
try {
$ErrorActionPreference = 'Stop'
Start-BitsTransfer $downloadUrl -Description $assetName -Destination $assetDestinationFolder -Asynchronous | Out-Null
}
catch {
#If too many transfers are queued at once the process begins to fail. This takes care of that problem.
while ($true) {
Write-Host "Queue full. Waiting for other downloads to finish. $((Get-BitsTransfer).Count) downloads in progress." -ForegroundColor Yellow
Start-Sleep -Seconds 1
Get-BitsTransfer | Format-Table -Property Description, JobState
Get-BitsTransfer | Where-Object { $_.JobState -eq "Transferred" } | Complete-BitsTransfer
Get-BitsTransfer | Where-Object { $_.JobState -like "*Error" -or $_.JobState -eq "Cancelled" } | ForEach-Object { $_ | Remove-BitsTransfer }
try {
Start-BitsTransfer $downloadUrl -Description $assetName -Destination $assetDestinationFolder -Asynchronous | Out-Null
break;
}
catch {
continue;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.