What leads to 'objectdisposedexception in c#?'


StreamReader sr = new StreamReader("path.txt");
string line = sr.ReadLine();

Trying to use an object after disposing of it.


This exception occurs when you try to access a disposed object. Always check if an object is disposed before using it, or ensure proper order of operations.

if(sr != null && !sr.EndOfStream) {
    string line = sr.ReadLine();

Beginner's Guide to C#