Bugs

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ayende Rahien

    Bugs

    Recently I've encountered two highly annoying bugs in the framework,
    anyone who knows how to solve them would be most appriciated.

    1) I'm trying to do Process.Start(u rl); and get a Win32Exception, after
    quite a bit of testing I found out that the reason for this is that I
    didn't have STAThread attribute. Process.Start(u rl) throws when I don't
    have an attribute at all, or when I have MTAThrea, anyone can tell me
    why?
    I looked around, and it seemed that many other people have encountered
    this problem. I've the workaround, but I want to know what is going on
    here!

    2) The following code throw an exception and abort the program, it
    shouldn't!

    public static void SetExceptionHan dlers()
    {
    System.AppDomai n.CurrentDomain .UnhandledExcep tion+=new
    UnhandledExcept ionEventHandler (CurrentDomain_ UnhandledExcept ion);
    System.Windows. Forms.Applicati on.ThreadExcept ion+=new
    System.Threadin g.ThreadExcepti onEventHandler
    (Application_Th readException);
    }

    public static void HandleException (Exception ex)
    {
    if(ex==null)
    return;
    using(DetailedE rrorInfo dei = new DetailedErrorIn fo(ex))
    {
    dei.ShowDialog( );
    }
    }

    private static void CurrentDomain_U nhandledExcepti on(object sender,
    UnhandledExcept ionEventArgs e)
    {
    HandleException (e.ExceptionObj ect as Exception);
    }

    private static void Application_Thr eadException(ob ject sender,
    System.Threadin g.ThreadExcepti onEventArgs e)
    {
    HandleException (e.Exception);
    }
    [ STAThread()]
    public static void Main(string [] args)
    {
    SetExceptionHan dlers();
    Test();
    Console.WriteLi ne("Test passeed");

    private void Test()
    {
    throw new InvalidOperatio nException("Tes t");
    }

    There is nothing wrong here as far as I can tell, but it still will give
    me the silly default dialog. The whole point is to have a better dialog
    there!

    3) Not related to bugs, but does anyone knows whatever there is a way to
    know at *runtime* whatever this is a debug or release build?


  • Jochen Kalmbach

    #2
    Re: Bugs

    Ayende Rahien wrote:
    [color=blue]
    > 3) Not related to bugs, but does anyone knows whatever there is a way
    > to know at *runtime* whatever this is a debug or release build?[/color]

    The main problem that you first have to define: What is the different
    between release and debug build?

    From the CLR-View the only difference is the
    "System.Diagnos tics.Debuggable Attribute"-Attribute.

    This attribute has two properties:
    - IsJITTrackingEn abled
    - IsJITOptimizerD isabled

    If both are "false", then you have a release build.

    See:
    Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

    us/cpref/html/frlrfsystemdiag nostics
    debuggableattri buteclasstopic. asp


    An other difference might be the generation of PDB-Files. But the
    current VS2002/2003 only support the generation of PDB-files with boths
    attribut-members set to "true".

    If you compile via command-line you can build a release version (no
    DebuggableAttri bute-Attribute or both set to false) AND have a PDB-file
    generated.


    --
    Greetings
    Jochen

    Do you need a memory-leak finder ?


    Do you need daily reports from your server?
    Download SrvReport for free. SrvReport is a simple and featurefull server monitoring and reporting system. It will send every day a mail with the latest state of the server including traffic (via /proc/net/dev and/or iptables), cpu, mail, http, ftp reports and other logs.

    Comment

    • Jochen Kalmbach

      #3
      Re: Bugs

      Ayende Rahien wrote:
      [color=blue]
      > 1) I'm trying to do Process.Start(u rl); and get a Win32Exception, after
      > quite a bit of testing I found out that the reason for this is that I
      > didn't have STAThread attribute. Process.Start(u rl) throws when I don't
      > have an attribute at all, or when I have MTAThrea, anyone can tell me
      > why?[/color]

      Can you please provide a working example !?
      Are you using "UseShellExecut e" or normal start with "CreateProc ess" !?

      --
      Greetings
      Jochen

      Do you need a memory-leak finder ?


      Do you need daily reports from your server?
      Download SrvReport for free. SrvReport is a simple and featurefull server monitoring and reporting system. It will send every day a mail with the latest state of the server including traffic (via /proc/net/dev and/or iptables), cpu, mail, http, ftp reports and other logs.

      Comment

      • Ayende Rahien

        #4
        Re: Bugs


        "Jochen Kalmbach" <nospam-Jochen.Kalmbach @holzma.de> wrote in message
        news:Xns94C0C71 58ED24nospamJoc henKalmbach@207 .46.248.16...[color=blue]
        > Ayende Rahien wrote:
        >[color=green]
        > > 1) I'm trying to do Process.Start(u rl); and get a Win32Exception, after
        > > quite a bit of testing I found out that the reason for this is that I
        > > didn't have STAThread attribute. Process.Start(u rl) throws when I don't
        > > have an attribute at all, or when I have MTAThrea, anyone can tell me
        > > why?[/color]
        >
        > Can you please provide a working example !?
        > Are you using "UseShellExecut e" or normal start with "CreateProc ess" !?
        >[/color]

        This is the full source code that cause the problem:

        public class Test
        {
        [System.MTAThrea d()]//NOTICE this, without this, everything works.
        public static void Main(string []args)
        {
        System.Diagnost ics.Process.Sta rt("http://www.google.com" );
        }
        }

        Cause Win32Exception with "The requested section was not present in the
        activation context"


        I can't repreduce the problem of no *Thread attribute in a simple example
        (complex stuff about threading and winforms.


        Comment

        • Willy Denoyette [MVP]

          #5
          Re: Bugs

          The ThreadAttribute can't be the problem source.

          Willy.


          "Ayende Rahien" <Ayende@no.spam > wrote in message
          news:erO7QWbGEH A.3568@tk2msftn gp13.phx.gbl...[color=blue]
          >
          > "Jochen Kalmbach" <nospam-Jochen.Kalmbach @holzma.de> wrote in message
          > news:Xns94C0C71 58ED24nospamJoc henKalmbach@207 .46.248.16...[color=green]
          >> Ayende Rahien wrote:
          >>[color=darkred]
          >> > 1) I'm trying to do Process.Start(u rl); and get a Win32Exception, after
          >> > quite a bit of testing I found out that the reason for this is that I
          >> > didn't have STAThread attribute. Process.Start(u rl) throws when I don't
          >> > have an attribute at all, or when I have MTAThrea, anyone can tell me
          >> > why?[/color]
          >>
          >> Can you please provide a working example !?
          >> Are you using "UseShellExecut e" or normal start with "CreateProc ess" !?
          >>[/color]
          >
          > This is the full source code that cause the problem:
          >
          > public class Test
          > {
          > [System.MTAThrea d()]//NOTICE this, without this, everything works.
          > public static void Main(string []args)
          > {
          > System.Diagnost ics.Process.Sta rt("http://www.google.com" );
          > }
          > }
          >
          > Cause Win32Exception with "The requested section was not present in the
          > activation context"
          >
          >
          > I can't repreduce the problem of no *Thread attribute in a simple example
          > (complex stuff about threading and winforms.
          >
          >[/color]


          Comment

          • Ayende Rahien

            #6
            Re: Bugs


            "Willy Denoyette [MVP]" <willy.denoyett e@pandora.be> wrote in message
            news:e4u2mhbGEH A.2472@TK2MSFTN GP10.phx.gbl...[color=blue]
            > The ThreadAttribute can't be the problem source.[/color]

            Test it, then.
            Using MTAThread - exception
            Using STAThread - working
            Not using at all - works (but I'd some problems with that)


            Comment

            • Willy Denoyette [MVP]

              #7
              Re: Bugs

              Sorry my bad, that's why I'm allways using ProcessStartInf o to start an
              external process, that way I wont be bitten by shell COM threading issues.

              ProcessStartInf o sti = new ProcessStartInf o("IExplore.exe ");
              sti.Arguments = "www.google.com ";
              sti.UseShellExe cute = true;
              Process.Start(s ti);

              Willy.

              "Ayende Rahien" <Ayende@no.spam > wrote in message
              news:%23egELybG EHA.1968@TK2MSF TNGP12.phx.gbl. ..[color=blue]
              >
              > "Willy Denoyette [MVP]" <willy.denoyett e@pandora.be> wrote in message
              > news:e4u2mhbGEH A.2472@TK2MSFTN GP10.phx.gbl...[color=green]
              >> The ThreadAttribute can't be the problem source.[/color]
              >
              > Test it, then.
              > Using MTAThread - exception
              > Using STAThread - working
              > Not using at all - works (but I'd some problems with that)
              >
              >[/color]


              Comment

              • Ayende Rahien

                #8
                Re: Bugs


                "Willy Denoyette [MVP]" <willy.denoyett e@pandora.be> wrote in message
                news:eyZnTFcGEH A.2612@TK2MSFTN GP09.phx.gbl...[color=blue]
                > Sorry my bad, that's why I'm allways using ProcessStartInf o to start an
                > external process, that way I wont be bitten by shell COM threading issues.
                >
                > ProcessStartInf o sti = new ProcessStartInf o("IExplore.exe ");
                > sti.Arguments = "www.google.com ";
                > sti.UseShellExe cute = true;
                > Process.Start(s ti);
                >[/color]

                And that is nice, but what if the user's default browser is
                Mozilla/Opera/Netscape/Non-IE?


                Comment

                • Spire

                  #9
                  Re: Bugs

                  read before responding

                  ProcessStartInf o sti = new ProcessStartInf o("IExplore.exe "); (use
                  path/opera.exe)[color=blue]
                  >
                  > And that is nice, but what if the user's default browser is
                  > Mozilla/Opera/Netscape/Non-IE?
                  >
                  >[/color]


                  Comment

                  • Ayende Rahien

                    #10
                    Re: Bugs

                    I don't *know* what the user's default browser is!
                    Yes, I can find out, but that is too much trouble.

                    I can also do this:
                    Process.Start(" cmd /c start " + url);

                    Which will also work (and give me the default browser), but I don't want to
                    use this (works on winnt only), I want to know what is wrong here.


                    "Spire" <spire2nospam@m ail.com> wrote in message
                    news:c4nf4k$5do $1@ls219.htnet. hr...[color=blue]
                    > read before responding
                    >
                    > ProcessStartInf o sti = new ProcessStartInf o("IExplore.exe "); (use
                    > path/opera.exe)[color=green]
                    > >
                    > > And that is nice, but what if the user's default browser is
                    > > Mozilla/Opera/Netscape/Non-IE?
                    > >
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    • Willy Denoyette [MVP]

                      #11
                      Re: Bugs

                      What is wrong here is simply that doing it 'your way - using Shell API's
                      under the covers', the calling thread must be running in an STA.

                      For more info read this (especially the remarks):


                      Willy.

                      "Ayende Rahien" <Ayende@no.spam > wrote in message
                      news:e2uRp9cGEH A.1912@TK2MSFTN GP10.phx.gbl...[color=blue]
                      >I don't *know* what the user's default browser is!
                      > Yes, I can find out, but that is too much trouble.
                      >
                      > I can also do this:
                      > Process.Start(" cmd /c start " + url);
                      >
                      > Which will also work (and give me the default browser), but I don't want
                      > to
                      > use this (works on winnt only), I want to know what is wrong here.
                      >
                      >
                      > "Spire" <spire2nospam@m ail.com> wrote in message
                      > news:c4nf4k$5do $1@ls219.htnet. hr...[color=green]
                      >> read before responding
                      >>
                      >> ProcessStartInf o sti = new ProcessStartInf o("IExplore.exe "); (use
                      >> path/opera.exe)[color=darkred]
                      >> >
                      >> > And that is nice, but what if the user's default browser is
                      >> > Mozilla/Opera/Netscape/Non-IE?
                      >> >
                      >> >[/color]
                      >>
                      >>[/color]
                      >
                      >[/color]


                      Comment

                      Working...