Mike Flynn
Mike Flynn

Reputation: 24325

IIS Hang when reading XML with StreamReader in .NET

Our diagnostic service said there was a hang at this position of our code. Is there anything that is shown that could cause a hang when reading a XML file with StreamReader?

STACK_TEXT:  
000000e1`8225cef8 00007ffa`b93f8eb8     : 00000000`00000002 00000000`00000000 00007ffa`b1ef6cdf 000000e1`8225cdd8 : ntdll!NtReadFile+0xa
000000e1`8225cf00 00007ffa`b0b3c9c8     : 00000000`00001000 00000000`00000000 00000000`00000018 000000e1`8225d098 : KERNELBASE!ReadFile+0x74
000000e1`8225cf80 00007ffa`b0a8e803     : 000000e3`d59a39d8 000000e3`d5b65b00 000000e3`d59a3ea8 00000000`00000400 : mscorlib_ni+0x63c9c8
000000e1`8225d060 00007ffa`b0a8e75d     : 000000e3`d5ec4bd8 00000000`00001000 00000000`00000000 000000ee`f3acbb90 : mscorlib_ni!System.IO.FileStream.ReadFileNative+0x83
000000e1`8225d0c0 00007ffa`b0a8e68a     : 00000000`00000000 000000e3`d5b65b30 000000e3`d5b65300 00007ffa`b0a775db : mscorlib_ni!System.IO.FileStream.ReadCore+0x5d
000000e1`8225d130 00007ffa`b0b082d4     : 000000e3`d5b65b30 00007ffa`b0a8e898 00000000`00000001 000000e3`d59a39f8 : mscorlib_ni!System.IO.FileStream.Read+0x13a
000000e1`8225d190 00007ffa`b0b09fab     : 00000000`00000000 00000000`00000000 00007ffa`b1f30d35 000000e1`8225cef8 : mscorlib_ni!System.IO.StreamReader.ReadBuffer+0x44
000000e1`8225d1e0 00007ffa`57ffff6d     : 00007ffa`b05a5188 00000000`00000004 000000e3`d598bf58 00007ffa`52e4d508 : mscorlib_ni!System.IO.StreamReader.ReadToEnd+0x8b
000000e1`8225d230 00007ffa`57fe774a     : 000000e3`d598bf58 000000e3`d59a3688 fffffff8`00000004 00000000`00000000 : Tournaments_Services!Tournaments.Services.Statistics.StatCrewService.ParseXml+0xbd

Code

private IGameCastGame ParseXml(string fileLocation, StatisticsType statisticsType)
{
    XDocument xDocument;

    try
    {
        using (var fileStream = new FileStream(
            fileLocation,
            FileMode.Open,
            FileAccess.Read,
            FileShare.ReadWrite))
        {
            using (var streamReader = new StreamReader(fileStream))
            {
                xDocument = XDocument.Parse(streamReader.ReadToEnd());
            }
        }
    }
    catch (Exception ex)
    {
        Logger.Error(ex);
        return null;
    }

    return StatCrewGame.Create(xDocument, statisticsType).Parse();
}

Upvotes: 0

Views: 30

Answers (0)

Related Questions