title: Cannot process argument transformation on parameter error while calling function in powershell
body: <p>I have a powershell script in which I am generating xml file.</p>
  
  <p>My script is as below:</p>
  
  <pre><code>$filePath= "C:\Powershell\Report.xml"
  if(Test-Path $filePath)
  {
      Remove-Item $filePath
  } 
  
  #set encoding
  $encoding = [System.Text.Encoding]::UTF8
  
  # Create The Document
  $XmlWriter = New-Object System.XMl.XmlTextWriter($filePath,$encoding)
  
  # Set The Formatting
  $xmlWriter.Formatting = "Indented"
  $xmlWriter.Indentation = "4"
  
  # Write the XML Decleration
  $xmlWriter.WriteStartDocument()
  
  SetNamespace($xmlWriter)
  
  # Write Root Element
  $xmlWriter.WriteStartElement($RootElement)
  
  #set Root Element namespaces
  SetRootElementNamespace($xmlWriter)
  
  #Create &lt;my:PruefAuftragHeader&gt;
  
  $Ablagenummer = "234"
  $Beschrieb = "This is testing"
  $Auftraggeber = @("ADAMS","Alu König Stahl","Caradon")
  
  CreatePruefAuftragHeader($xmlWriter ,$Ablagenummer)
  
  
  
  Function CreatePruefAuftragHeader([System.Xml.XmlTextWriter] $xmlWriter ,[String] $Ablagenummer)
  {
      $xmlWriter.WriteStartElement($PruefAuftragHeaderElement) # opening &lt;my:PruefAuftragHeader&gt;
  
      $xmlWriter.WriteElementString($AblagenummerElement,$Ablagenummer)
      $xmlWriter.WriteElementString($BeschriebElement,$Beschrieb)
  
      foreach($elem in $Auftraggeber)
      {
          $xmlWriter.WriteElementString($AuftraggeberElement,$elem)
      }
  
      $xmlWriter.WriteEndElement #closing &lt;my:PruefAuftragHeader&gt;
  }
  </code></pre>
  
  <p>When execution reaches at line : <code>CreatePruefAuftragHeader($xmlWriter ,$Ablagenummer)</code> it throws an error : <code>Cannot process argument transformation on parameter 'xmlWriter'. Cannot convert the "System.Object[]" value of type "System.Object[]" to type 
  "System.Xml.XmlTextWriter".</code> </p>
  
  <p>What should I do to tackle the error?</p>