We've run into similar obstacles on my team. Some commenters have suggested that developers need to be more okay with using files. If it's an option to use the filesystem directly do that, but that's not always an option.
If, like we needed, you want to pass data read from a file around your application, you can't pass the FileStream object because it can get disposed before you're done reading the data. We originally resorted to MemoryStreams to let us pass the data around easily, but ran into the same problem.
We've used a couple different workarounds to mitigate the problem.
Options we've used include:
- Implement a wrapper class to store the data in multiple (since arrays are still limited to
int.MaxValue
number of entries) byte[] objects and expose methods that enable you to almost treat them like a Stream. We still try to avoid this at all costs.
- Use some sort of "token" to pass a reference to the location of the data and wait to load the data "just in time" in the application.