none
Exception calling "ExecuteQuery" with "0" argument(s): "Root element is missing." RRS feed

  • Question

  • #Specify tenant admin and site URL

    $User = "UserName" $ListTitle = "NewList" #Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" $Password = Read-Host -Prompt "Please enter your password" -AsSecureString #Bind to site collection $SiteURL="MySite" write-host $SiteURL $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) #Authenticate $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password) $Context.Credentials = $Creds write-host "Passed Credential Check" #Create list with "custom" list template $ListInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation $ListInfo.Title = $ListTitle $ListInfo.TemplateType = "100" $List = $Context.Web.Lists.Add($ListInfo) $List.Description = $ListTitle $List.Update() write-host "After $List.Update()" -foregroundcolor Green $Context.ExecuteQuery() write-host "done"

    I am learning to use Powershell script.  I am attempting to create a List named "NewList" to my SharePoint Site via the above Powershell script.  I got Exception calling "ExecuteQuery" with "0" argument(s): "Root element is missing." 

    On this machine, the PSVersion is 5.1.17134.858 (Windows 10)

    When I run the same script on another machine with the same PS Version (Windows 10), I got the same error.  

    When I run the same script on another machine with PS Version 5.1.16299.251 (Windows 10) or 4.0 (Windows Server 2012 R2).

    I tried setting DNS address to 8.8.8.8 and 8.8.8.4 from this link.   It did not change anything for me. 

    I tried re-installing Powershell as instructed by this link

    Any idea to fix this issue on this machine? 

    Thanks .

    Dan Chan

    Monday, August 19, 2019 6:34 PM

All replies

  • Hi,

    Thanks for your question.

    Based on the complexity and the specific situation, we need do more researches. If we have any updates or any thoughts about this issue, we will keep you posted as soon as possible. Your kind understanding is appreciated. If you have further information during this period, you could post it on the forum, which help us understand and analyze this issue comprehensively.
    Sorry for the inconvenience and thank you for your understanding and patience.

    Best regards,

    Lee


    Just do it.

    Tuesday, August 20, 2019 6:28 AM
    Moderator
  • Hi Lee,

    I ran my script in Windows PowerShell ISE and got the following error.  I also attached the $PSVersionTable

    Tuesday, August 20, 2019 12:17 PM
  • Running the script in PS 6 does not help. 

    When I did a $StackTrace, I got the following.  It seemed that $Context.ExecuteQuery() created an XML file that has the WRONG format to be decoded.  If it is true, where is the XML file?  

    Tuesday, August 20, 2019 6:01 PM
  • The code generates SOAP queries.  SOAP is transmitted as XML.  The error means that you have bad or missing arguments in you request.


    \_(ツ)_/

    Tuesday, August 20, 2019 6:24 PM
    Moderator
  • SOLVED!!!! 

    Well, I am learning Powershell.  So, somehow, I got the idea to play with time and got the below DateTimeExample script going.  It ran without any problems, producing the expected results.  

    $Date1=(Get-Date)
    $Date1
    write-host 'Get System Date'
    $Date1.ToSTring("yyyyMMdd")
    $Date1.ToSTring("HHmmss")
    write-host 'yyyyMMDD and HHmmSS from System Date'
    $A1='2014-02-10 12:47:27'
    $A1
    $A=[DateTime]::ParseExact($A1,'yyyy-MM-dd HH:mm:ss',$null)
    $A.IsDaylightSavingTime()
    if ($A.IsDaylightSavingTime()) {
        $A=$A.AddHours(4)
        }
        else {
        $A=$A.AddHours(5)
    }
    $A.ToString("yyyyMMddHHmmss")
    write-host 'Convert a String to DateTime'

    The STRANGE part is that after running the above script and then go back to run my script to load/create a list in SharePoint, the "Root Element is missing" error WENT AWAY?! 

    As I said previously, I had problem on both my desktop and laptop with the same PS Version.

    First, my desktop was able to run the load/create a list script without problem.

    Then, I tested all the things I did in between.  I found that after running the above DateTimeExample Script, the "Root Element is missing" error went away.  

    Wednesday, August 21, 2019 6:17 PM
  • The error was correct.  Without a correct datetime it will fail.

    $a1='2014-02-10 12:47:27'
    [datetime]$a1

    Don't use parse for this and your issues will go away.  Add error detection and don't proceed when there are errors.

    Most important - learn PowerShell correctly before continuing.  It will save you wasted time and bad guesses.


    \_(ツ)_/

    Wednesday, August 21, 2019 6:23 PM
    Moderator
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Friday, September 6, 2019 12:07 PM
    Moderator