How can I store dialogue so that it could be read for a kinetic (linear) Visual Novel type of game in XNA/MonoGame?

I'm currently using a .txt file, but I noticed that I can't read from a specific line using the System.IO.StreamReader class.

  • 1
    \$\begingroup\$ The irony. An Alex helping another Alex. \$\endgroup\$ Commented Jul 2, 2018 at 14:33

1 Answer 1


You'll want to use TitleContainer.OpenStream in place of the stream reader.

The reason they do it differently in XNA / MonoGame is for cross platform compatibility. Essentially, the TitleContainer abstracts away the details about how to read the file on whatever platform you're targeting.

There's also two other things you'll need to be aware of:

  1. When you're loading raw content that isn't processed with the Content Pipeline tool, you'll need to set the properties of the file in Visual Studio to Content and Copy if newer.
  2. You'll need to use the path and file extension (not just the name like you would with Content.Load

For example:

using (var stream = TitleContainer.OpenStream("Content/data.txt"))
using (var reader = new StreamReader(stream))
    // Do your thing here as you normally would
  • \$\begingroup\$ Thanks! That explains a lot. I didn't know about the existence of TitleContainer beforehand. \$\endgroup\$
    – Alexandre
    Commented Sep 4, 2017 at 14:45
  • \$\begingroup\$ Now I'm only curious if it's required to use the "using" keyword. \$\endgroup\$
    – Alexandre
    Commented Sep 4, 2017 at 15:07
  • \$\begingroup\$ The using statement is shorthand for a try finally block. It's designed to safely dispose of the stream when it's no longer in use even if exceptions are thrown. In some circumstances you might want call Dispose yourself (e.g. if you want to hang on to a reference to the stream for more than one method call) but designing your code this way often makes things more complex. My advice, start with the simplest thing that works. \$\endgroup\$ Commented Sep 5, 2017 at 10:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .