[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


https://bugzilla.novell.com/show_bug.cgi?id=357649


           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
HTMLMessage)

{

    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;

        myProcess.Start();

        sw = myProcess.StandardInput;

    }

    else

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

                                           string.Format("{0}{1}.eml",
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)

                             .Replace("%%USERS%%",
Configuration.SanitizeEmails(users, ", "))

                             .Replace("%%SENDER%%",
Configuration.SanitizeEmails(Configuration.Sender, "")));

    sw.Close();

    sw.Dispose();

}


----------------------

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