6

I'm trying to read the contents of a .csproj file using sharpsvn, but I seem to be always getting an empty file back.

Here is my code:

MemoryStream myOut = new MemoryStream();       
svnClient.Write(path, myOut))
return myOut.GetLibsFromCsproj();

private static string GetLibsFromCsproj(this MemoryStream csjpros)
{
    TextReader tr = new StreamReader(csjpros);
    XElement projectNode = XElement.Load(tr);
    XNamespace msbuild = "http://schemas.microsoft.com/developer/msbuild/2003";
    var referenceNodes = projectNode.Descendants(msbuild + "ItemGroup").Descendants(msbuild + "Reference").ToString();
    return referenceNodes;
}

When my code gets to XElement.Load(tr);, it throws an error saying that root element is missing. It turns our that myOut is empty.

Am I doing something wrong?

CD Smith
  • 6,597
  • 7
  • 40
  • 66
RJP
  • 4,016
  • 5
  • 29
  • 42
  • this may be helpfull dude [The SharpSvn.SvnClient class has a GetList() function that works really well:](http://stackoverflow.com/a/5679545/1239836) – Devendar Jun 14 '12 at 11:06

2 Answers2

8

Did you remember to reset the MemoryStream back to the beginning after writing into it? Try adding this line before the return statement:

myOut.Seek(0, SeekOrigin.Begin);
Allon Guralnek
  • 15,813
  • 6
  • 60
  • 93
  • Even adding this, myOut is no longer null, but it is empty. If I perform the same operation using a FileStream, it will write everything to the file just fine. – RJP Jun 08 '12 at 16:33
2

perhaps this is helpful:

How to read each revision of file using sharpsvn client using c#

Community
  • 1
  • 1
Mare Infinitus
  • 8,024
  • 8
  • 64
  • 113