Error You cannot call a method on a null-valued express

Welcome Forums General PowerShell Q&A Error You cannot call a method on a null-valued express

Viewing 1 reply thread
  • Author
    Posts
    • #238712
      Participant
      Topics: 11
      Replies: 15
      Points: 104
      Rank: Participant

      When I try to run this script it shows error message

      Above code works but it shows a error message

      You cannot call a method on a null-valued expression.
      At Update_IMDB_id.ps1:24 char:13
      + $newXmlElement = $tvshow.AppendChild($childElement)
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull

      • This topic was modified 2 months, 2 weeks ago by kvprasoon. Reason: code formatting
    • #240101
      Senior Moderator
      Topics: 9
      Replies: 1309
      Points: 4,781
      Helping Hand
      Rank: Community Hero

      Make sure $fileData.tvshow is returning an object. You can VSCode or ISE to debug by putting a break point or atleast try to print $fileData.tvshow to make sure it returns a valid object.

      If $fileData.tvshow returns null, then $tvshow variable becomes null and a null value wont have a method to get called.

      • This reply was modified 2 months, 2 weeks ago by kvprasoon. Reason: post correction
Viewing 1 reply thread
  • You must be logged in to reply to this topic.