This is part of a Visual Studio 2017 application being developed on a Windows 10 box. Here is my code. I've tried various configurations but the result stays the same. Not sure where to go from here.

The actual error is thrown when the cnx.ExecuteQuery() line runs. The user name and password are drawn from the config file without error.

        private string SaveFile(string fileName, byte[] fileContent)
            string retVal = string.Empty;
                string spSiteUrl = "https://<mysite>.sharepoint.com/SitePages/TestFiles";
                string username = Convert.ToString(ConfigurationManager.AppSettings["KeyUserName"]);
                string password = Convert.ToString(ConfigurationManager.AppSettings["KeyPassword"]);
                using (ClientContext cnx = new ClientContext(spSiteUrl))

                    SecureString secret = new SecureString();
                    foreach (char c in password)
                    cnx.Credentials = new SharePointOnlineCredentials(username, secret);
                    Web w = cnx.Web;
                    cnx.Load(w, website => website.Lists, website => website.ServerRelativeUrl);

                    retVal = "Success";
            catch (Exception ex)
                MessageBox.Show(ex.Message + Environment.NewLine + ex.InnerException);
            return retVal;

3 Answers 3


This is a known issue specific to the particular machine where you are executing this code. In order to fix this issue, need to change the DNS setting in your machine.

Follow the below steps to change the DNS setting :

  1. Go to Control Panel --> Network and Internet --> Change Adapter Settings --> Select the Network through which you are connecting to Internet
  2. Right click on it and Select Properties. Then select Internet Protocol Version 4 (TCP/IPV4) and select properties
  3. Then select the "Use the following DNS Server Addresses" instead obtain DNS server addresses automatically and give the DNS whatever you want. Here i gave the free DNS address which is offered by google.
  4. Google public DNS addresses : and 
  5. Then say OK to apply these changes.

Then run the code, it will work.

For details steps, follow the below article :

Root Element Missing when connecting to SharePoint online via CSOM/Powershell on windows 10 machine

  • I agree that you probably need to change DNS. I would lean more towards a DNS provider that is less likely to track you, however. I choose CloudFlare ( with alternate See also: beebom.com/best-dns-servers Jul 13, 2021 at 16:04

In addition to specifying the DNS addresses (as mentioned above), I also had to disable (uncheck): Internet Protocol Version 6 (TCP/IPv6). Confirmed that using my automatically obtained DNS OR keeping IPv6 enabled, would cause the issue in my environment.


We've recently had this error on two previously working customers. Your post pointed me in the right direction. In our case, it was caused by the server connecting to SharePoint being unable to resolve msoid.customerdomain.com. One was missing, the other had no entry on their internal DNS. Instead the DNS server returned an IP for msoid.com, which didn't return the expected XML document, and hence the error in your post. Hopefully that might help someone else who has just started seeing this error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.