【发布时间】:2019-09-23 22:07:39
【问题描述】:
我有一个 PowerShell 脚本,我想在其中以某种方法设置一个值。 我使用了一个 dll,而我现在这些方法都存在于这个 dll 文件中。
但由于某种原因,我仍然收到方法未找到异常。
我在我的脚本中更新了 dll 并打印了文件名,所以我确信我的脚本使用了正确的 dll。 我检查了dll并且该方法存在。
在同一个文件中,我使用了另一种方法,效果很好。
我想也许我写错了,但没有找到。
$messagingDllPath = Join-Path -Path $PSScriptRoot -ChildPath 'dll/OneHIP.Messaging.dll' | Resolve-Path
Add-Type -Path $messagingDllPath # Add assembly
[OneHIP.Messaging.Configuration.ApplicationSettingsProvider]::SetValue("ClientId","idValue")
[OneHIP.Messaging.Configuration.ApplicationSettingsProvider]::SetValue("ClientSecret","secret")
<member name="M:OneHIP.Messaging.Configuration.ApplicationSettingsProvider.SetValue(System.String,System.String)">
<inheritdoc/>
</member>
2019-09-23T08:18:30.3228501Z ##[error]ValidateBusConfiguration : System.Management.Automation.RuntimeException: Metho
d invocation failed because [OneHIP.Messaging.Configuration.ApplicationSettings
Provider] doesn't contain a method named 'SetValue'.
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(F
unctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(Inte
rpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.
Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.
Run(InterpretedFrame frame)
At \\eqx-prd-ohfs.appliarmony.net\MSG\OneHipConfigurationValidationTfsBuildTask
\ValidateOneHIPConfiguration.ps1:217 char:9
+ ValidateBusConfiguration
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorExcep
tion
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorExceptio
n,ValidateBusConfiguration
有人知道这里有什么问题吗?
【问题讨论】:
-
我觉得这个函数叫SetPropertyValues
-
在我们的代码中,我们确实有一个名为 Set Value 的方法。 public string SetValue(string settingName, string value) { var oldValue = GetValue(settingName); _storedValues[settingName] = 值;返回旧值; }
-
你的方法是静态的吗?您正在使用 PowerShell 的静态方法调用约定(即使用
::运算符)。如果不是,您需要先创建您的类型的实例(使用New-Object),然后使用实例方法语法调用(即使用.运算符)。使用Get-Member:[TypeName] | Get-Member检查 PowerShell 是否知道该方法。添加-Static开关以查看静态方法。 -
谢谢,有问题,方法不是静态的。
-
酷。我添加了我的评论作为答案,以便将来更容易找到。随意接受它:-)
标签: powershell methods dll