System.Transactions.TransactionScope缺少函数 "new()"

问题描述 投票:0回答:1

我正在使用PowerShell来测试一下AlphaFS。在我的Windows 10开发环境中,这一行运行得很好。

PS C:\Users\Administrator [System.Transactions.TransactionScope]::new([System.Transactions.TransactionScopeOption]::Re
uiresNew)

在Windows Server 2012 R2上抛出了一个异常。

Method invocation failed because [System.Transactions.TransactionScope] does not contain a method named 'new'.
At line:1 char:1
+ [System.Transactions.TransactionScope]::new([System.Transactions.TransactionScop ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

唯一可以使用的方法是::Equals()和::ReferenceEquals().我无法得到任何关于该函数的信息,以及它的归属。我需要安装一个特定的.NET框架来使其工作吗?

感谢任何帮助。

.net powershell transactions transactionscope
1个回答
0
投票

::new() 静态构造函数调用方法最早是在 PowerShell 5.0.

Windows Server 2012 R2与PowerShell 4.0兼容。

对于5.0之前的兼容性,请使用 New-Object 而不是。

$transScope = New-Object System.Transactions.TransactionScope -ArgumentList ([System.Transactions.TransactionScopeOption]::RequiresNew)
© www.soinside.com 2019 - 2024. All rights reserved.