private void FinishInitUriString()
{
Stream stream = null;
if (_laterInitParam.useAsync)
{
//this will be hit when user create a XmlReader by setting Async, but the first call is Read() instead of ReadAsync(),
//then we still should create an async stream here. And wait for the method finish.
System.Threading.Tasks.Task<object> t = _laterInitParam.inputUriResolver.GetEntityAsync(_laterInitParam.inputbaseUri, string.Empty, typeof(Stream));
t.Wait();
stream = (Stream)t.Result;
}
else
{
stream = (Stream)_laterInitParam.inputUriResolver.GetEntity(_laterInitParam.inputbaseUri, string.Empty, typeof(Stream));
}
if (stream == null)
{
throw new XmlException(SR.Xml_CannotResolveUrl, _laterInitParam.inputUriStr);
}
Encoding enc = null;
// get Encoding from XmlParserContext
if (_laterInitParam.inputContext != null)
{
enc = _laterInitParam.inputContext.Encoding;
}
try
{
// init ParsingState
InitStreamInput(_laterInitParam.inputbaseUri, _reportedBaseUri, stream, null, 0, enc);
_reportedEncoding = _ps.encoding;
// parse DTD
if (_laterInitParam.inputContext != null && _laterInitParam.inputContext.HasDtdInfo)
{
ProcessDtdFromParserContext(_laterInitParam.inputContext);
}
}
catch
{
stream.Dispose();
throw;
}
_laterInitParam = null;
}