DTD resolution and network behavior

Following up from my last post, danieldsmith asked about a couple of additional details. I think I responded in the comments, but because (a) it's generally useful, and (b) I had some problems with my network connection (because I monkeying around with it), the reply may have been lost. So here we go again.

First, is caching implemented for the resolved DTDs? No, the default resolver doesn't do any cachingĀ - files will always be requested. So if you're loading documents with DTDs in a tight loop, you might get a pretty significant perf improvement here.

Second, what happens if there is no network connectivity? Well, the framework can't do validation without the DTD, and even if it could it would be unable to expand entities, so as you might guess, the problem isn't silently ignored - you'll get an exception instead.

Trying this on my machine at home, I got two slightly different exception - your mileage may vary. The first time I had Fiddler running, and I got a System.Net.WebException with a Message value "The remote server returned an error: (502) Bad Gateway.", and a Status value of ProtocolError. There was a Response assigned to it, which had a message of its own, "Fiddler - DNS Lookup Failed".

Then I shut down Fiddler and got another WebException, although this time the message was "The remote name could not be resolved: 'www.w3.org'", and the Response of the exception was null.

So now you know. Keep an eye on your network activity, and turn off features that you don't use to get perf / stability improvements without having to go and make changes to your application.

As a side note, I like to run Fiddler every now and then, just to see what kind of web traffic my machine is generating - it's awfully interesting to see the kinds of things that are going on sometimes.

Enjoy!