Exception “For security reasons DTD is prohibited in this XML document” Connecting to SharePoint Online with CSOM


A few times over the last year or so I’ve come across an error while trying to connect to SharePoint Online using CSOM;

Exception calling “ExecuteQuery” with “0” argument(s): “For security reasons DTD is prohibited in this XML document. To enable DTD processing set the Dtd Processing property on XmlReaderSettings to Parse and pass the settings into XmlReader.Create method.”

This post by Paul Ryan offers an explanation and solution, though in my case it didn’t quite work, I was using an account of the  <username>@<domain>.onmicrosoft.com variety to connect to SPO which Paul’s post indicates should work.

To fix the situation I had to add 2 entries to my local HOSTS files;

127.0.0.1   msoid.<domain>.onmicrosoft.com
127.0.0.1   msoid.onmicrosoft.com

The 2nd host entry is important as if the GET for FPurl.xml fails using the first msoid DNS entry, it then tries using the 2nd DNS entry, msoid.onmicrosoft.com, which does succeed and you are left in the same situation as before.

 

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

One thought on “Exception “For security reasons DTD is prohibited in this XML document” Connecting to SharePoint Online with CSOM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.