[Mono-bugs] [Bug 357649] New: GC Error: The object was used after being disposed.

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Jan 31 11:31:04 EST 2008


           Summary: GC Error: The object was used after being disposed.
           Product: Mono: Runtime
           Version: 1.2.6
          Platform: x86-64
        OS/Version: Linux
            Status: NEW
          Severity: Critical
          Priority: P5 - None
         Component: GC
        AssignedTo: lupus at novell.com
        ReportedBy: yhdezalvarez at gmail.com
         QAContact: mono-bugs at lists.ximian.com
                CC: yhdezalvarez at gmail.com
          Found By: Other

Unhandled Exception: System.ObjectDisposedException: The object was used after
being disposed.
  at System.IO.StreamWriter.Write (System.String value) [0x00000] 
  at System.IO.TextWriter.WriteLine (System.String value) [0x00000] 
  at mdu.Mailer.SendMail (System.String users, System.String TextMessage,
System.String HTMLMessage) [0x00000] 
  at mdu.Reporter.SendReport (mdu.UserDictionary Users, System.String
EMailList) [0x00000] 
  at mdu.Program.ProcessDirectory (System.IO.DirectoryInfo Dir, System.String
DefaultUser) [0x00000] 
  at mdu.Program.ProcessDirectory (System.IO.DirectoryInfo Dir, System.String
DefaultUser) [0x00000] 
  at mdu.Program.Main (System.String[] args) [0x00000]

code in question:
static public void SendMail(string users, string TextMessage, string


    StreamWriter sw;

    if (string.IsNullOrEmpty(Configuration.MailDir))


        Process myProcess = new Process();

        myProcess.StartInfo.FileName = "/usr/sbin/sendmail";

        myProcess.StartInfo.Arguments = string.Format("-f {0} -- {1}",

            Configuration.SanitizeEmails(Configuration.Sender, ""),

            Configuration.SanitizeEmails(users, " "));

        myProcess.StartInfo.UseShellExecute = false;

        myProcess.StartInfo.RedirectStandardInput = true;


        sw = myProcess.StandardInput;



        sw = new StreamWriter(Path.Combine(Configuration.MailDir,

C++.ToString("000"), users)));

    string line;

    using (StreamReader sr = new StreamReader(Configuration.EMailTemplate))

        while ((line = sr.ReadLine()) != null)

            sw.WriteLine(line.Replace("%%TEXT%%", TextMessage)

                             .Replace("%%HTML%%", HTMLMessage)

Configuration.SanitizeEmails(users, ", "))

Configuration.SanitizeEmails(Configuration.Sender, "")));





I think this happens because:
* the variable myProcess goes out of scope
* GC collection occurs before sw.WriteLine is called.

But the GC should keep the stream myProcess.StandardInput because it's
referenced by sw. Isn't it?

In the meantime I'm gonna move the declaration of myProcess out to the parent
block to workaround this.

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

More information about the mono-bugs mailing list