This can be fixed by modifing XIncludeReader.CreateAcquiredInfoset(Uri includeLocation) to:
/// <summary>
/// Creates acquired infoset.
/// </summary>
private string CreateAcquiredInfoset(Uri includeLocation)
{
if (_cache == null)
_cache = new Dictionary<string, WeakReference>();
WeakReference wr;
if (_cache.TryGetValue(includeLocation.AbsoluteUri, out wr) && wr.IsAlive)
{
return (string)wr.Target;
}
else
{
//Not cached or GCollected
WebResponse wRes;
string content = null;
using (Stream stream = GetResource(includeLocation.AbsoluteUri,
_reader.GetAttribute(_keywords.Accept),
_reader.GetAttribute(_keywords.AcceptLanguage), out wRes))
{
using (XIncludingReader xir = new XIncludingReader(wRes.ResponseUri.AbsoluteUri, stream, _nameTable))
{
xir.WhitespaceHandling = _whiteSpaceHandling;
using (StringWriter sw = new StringWriter())
{
using (XmlTextWriter w = new XmlTextWriter(sw))
{
try
{
while (xir.Read())
w.WriteNode(xir, false);
}
finally
{
if (xir != null)
xir.Close();
if (w != null)
w.Close();
}
content = sw.ToString();
}
}
}
}
if (content != null)
{
lock (_cache)
{
if (!_cache.ContainsKey(includeLocation.AbsoluteUri))
_cache.Add(includeLocation.AbsoluteUri, new WeakReference(content));
}
}
return content;
}
}
Comments: ** Comment from web user: williware **
I was utilizing my own resolver. The call mentioned above (CreateAcquiredInfoset) is never executed. My resolver returns a stream. The stream was used to create the XmlBaseAwareXmlReader. The XmlBaseAwareXmlReader gets closed when popped, but the underlying stream is not by default. I added the line 'settings.CloseInput = true;' to all of the CreateReaderSettings functions. Code follows. I believe this is the correct default behavior because the stream was retrieved via an external resolver's GetEntity and this code would be the only place it can be closed.
private static XmlReaderSettings CreateReaderSettings() {
XmlReaderSettings settings = new XmlReaderSettings();
settings.ProhibitDtd = false;
settings.CloseInput = true;
return settings;
}
private static XmlReaderSettings CreateReaderSettings(XmlResolver resolver)
{
XmlReaderSettings settings = CreateReaderSettings();
settings.XmlResolver = resolver;
settings.CloseInput = true;
return settings;
}
private static XmlReaderSettings CreateReaderSettings(XmlNameTable nt)
{
XmlReaderSettings settings = CreateReaderSettings();
settings.NameTable = nt;
settings.CloseInput = true;
return settings;
}