Koen Rombout
Koen Rombout

Reputation: 257

powershell dll method not found

I have a PowerShell script where I want to set a Value in some method. I use a dll, and I now these methods exists in this dll file.

But for some reason, I still get a method not found exception.

I updated the dll and printed the filename, in my script, so I am sure that my script using the right dll. I checked the dll and the method exist.

In the same file, I have another method that I use, en this works perfectly.

I thought maybe I had a writing error but didn't found one.

$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

Does somebody have an idea what the problem is here?

Upvotes: 1

Views: 1006

Answers (2)

boxdog
boxdog

Reputation: 8442

Check if the method is known to PowerShell by using Get-Member:

$ObjectInstance | Get-Member

Add the -Static switch to see the static methods:

$ObjectInstance | Get-Member -Static

This latter option also works with types directly:

[TypeName] | Get-Member -Static

You are using PowerShell's static method calling convention (i.e. using the :: operator). If it isn't static (which you've since confirmed), you'll need to create an instance of your type first (with New-Object), then call with the instance method syntax (i.e. with the . operator).

Upvotes: 3

Koen Rombout
Koen Rombout

Reputation: 257

The method was not Static.

By creating a new instance, I was able to call the SetValue method.

Thanks to @boxdog

Upvotes: 0

Related Questions