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

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of shuchi shuchi 1 year, 3 months ago.

  • Author
    Posts
  • #32189
    Profile photo of shuchi
    shuchi
    Participant

    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.

  • #32200
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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)

  • #32432
    Profile photo of shuchi
    shuchi
    Participant

    Thanks for answering

You must be logged in to reply to this topic.