Error: Multiple ambiguous overloads found for "Find" and the argument count: "1"

Getting following exception while invoking C# functions from PowerShell 4.

Multiple ambiguous overloads found for “Find” and the argument count: “1”.
At D:\Test\sample2.ps1:19 char:1

  • $ctrl= $facade.Find([string]$cpath)

The PowerShell script used is as follows:

$fileDirectory = “D:\Test\runtime”;
foreach($file in Get-ChildItem $fileDirectory)
{
$filePath = $fileDirectory + “” + $file;

if ($file.Extension -like ‘.dll’)
{
Add-Type -Path $filePath
}
}

$facade = New-Object FullNamespace.Facade -argumentlist "D:\App.xml , $True
[string]$cpath = “App.Home.Logo”
$ctrl= $facade.Find([string]$cpath)

The definition of my C# class is as follows:
public class Facade
{
public Facade(string xMLPath, bool wait = false) {…}
public Control Find(string path, string id, string name) {…}
public Control Find(string path) {…}
public Control Find(string path, bool recog = true) {…}
}

Any help, pointers to resolve the error will be appreciated.

These two parts of your class definition look ambiguous to me. I wasn’t aware that C# would even allow this to compile:

public Control Find(string path) {..}
public Control Find(string path, bool recog = true) {..}

As a workaround in PowerShell, I’d probably just call the second overload by explicitly specifying the boolean parameter’s default value: $facade.Find($cPath, $true)

Thanks for answering