Catching Application Configuration Error...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?SmFzb24gUmljaG1laWVy?=

    Catching Application Configuration Error...

    Is there a way to catch an application configuration error on startup?

    I have written a windows service. If there is an error in the configuration
    file (such as invalid xml) the exception is thrown before the OnStart method
    is invoked. Is there a way to catch this exception?

    Thank you,

    Jason Richmeier
  • =?Utf-8?B?TW9ydGVuIFdlbm5ldmlrIFtDIyBNVlBd?=

    #2
    RE: Catching Application Configuration Error...

    Hi Jason,

    No, errors in the configuration files are thrown by .Net Framework before
    the application is loaded. If this is a common issue, consider using a
    separate configuration file and load it manually.

    --
    Happy Coding!
    Morten Wennevik [C# MVP]


    "Jason Richmeier" wrote:
    Is there a way to catch an application configuration error on startup?
    >
    I have written a windows service. If there is an error in the configuration
    file (such as invalid xml) the exception is thrown before the OnStart method
    is invoked. Is there a way to catch this exception?
    >
    Thank you,
    >
    Jason Richmeier

    Comment

    • Jeff Winn

      #3
      Re: Catching Application Configuration Error...

      Actually, configuration errors are thrown when the configuration is first
      accessed, not when the appdomain is being loaded. If your service is
      throwing an exception before OnStart is called you might want look at your
      code and make sure you aren't accessing the ConfigurationMa nager somewhere
      that would cause it to get thrown before the service has started.

      The service is created in your Program.cs file (assuming you're using Visual
      Studio), I'd start looking in there first. Also check your service class for
      any static variables or class variables that are being set as the class is
      being instantiated.

      "Morten Wennevik [C# MVP]" <MortenWennevik @hotmail.comwro te in message
      news:BE2C9C37-C859-4F85-B647-FE1F739A209A@mi crosoft.com...
      Hi Jason,
      >
      No, errors in the configuration files are thrown by .Net Framework before
      the application is loaded. If this is a common issue, consider using a
      separate configuration file and load it manually.
      >
      --
      Happy Coding!
      Morten Wennevik [C# MVP]
      >
      >
      "Jason Richmeier" wrote:
      >
      >Is there a way to catch an application configuration error on startup?
      >>
      >I have written a windows service. If there is an error in the
      >configuratio n
      >file (such as invalid xml) the exception is thrown before the OnStart
      >method
      >is invoked. Is there a way to catch this exception?
      >>
      >Thank you,
      >>
      >Jason Richmeier

      Comment

      • =?Utf-8?B?TW9ydGVuIFdlbm5ldmlrIFtDIyBNVlBd?=

        #4
        Re: Catching Application Configuration Error...

        Well, since the configuration files may contain sections meant for the CLR
        describing how the application is to be run, the configuration file is read
        prior to running any application code.

        --
        Happy Coding!
        Morten Wennevik [C# MVP]


        "Jeff Winn" wrote:
        Actually, configuration errors are thrown when the configuration is first
        accessed, not when the appdomain is being loaded. If your service is
        throwing an exception before OnStart is called you might want look at your
        code and make sure you aren't accessing the ConfigurationMa nager somewhere
        that would cause it to get thrown before the service has started.
        >
        The service is created in your Program.cs file (assuming you're using Visual
        Studio), I'd start looking in there first. Also check your service class for
        any static variables or class variables that are being set as the class is
        being instantiated.
        >
        "Morten Wennevik [C# MVP]" <MortenWennevik @hotmail.comwro te in message
        news:BE2C9C37-C859-4F85-B647-FE1F739A209A@mi crosoft.com...
        Hi Jason,

        No, errors in the configuration files are thrown by .Net Framework before
        the application is loaded. If this is a common issue, consider using a
        separate configuration file and load it manually.

        --
        Happy Coding!
        Morten Wennevik [C# MVP]


        "Jason Richmeier" wrote:
        Is there a way to catch an application configuration error on startup?
        >
        I have written a windows service. If there is an error in the
        configuration
        file (such as invalid xml) the exception is thrown before the OnStart
        method
        is invoked. Is there a way to catch this exception?
        >
        Thank you,
        >
        Jason Richmeier
        >

        Comment

        • =?Utf-8?B?SmFzb24gUmljaG1laWVy?=

          #5
          Re: Catching Application Configuration Error...

          I had pretty much come to this conclusion. I wasn't sure if there was
          anything that I could put in the Startup class (where Main is located) to
          trap the error. I do like the idea you presented. My configuration file has
          a custom configuration section so I have to manually load this section anyway.

          Thank you,

          Jason Richmeier

          "Morten Wennevik [C# MVP]" wrote:
          Well, since the configuration files may contain sections meant for the CLR
          describing how the application is to be run, the configuration file is read
          prior to running any application code.
          >
          --
          Happy Coding!
          Morten Wennevik [C# MVP]
          >
          >
          "Jeff Winn" wrote:
          >
          Actually, configuration errors are thrown when the configuration is first
          accessed, not when the appdomain is being loaded. If your service is
          throwing an exception before OnStart is called you might want look at your
          code and make sure you aren't accessing the ConfigurationMa nager somewhere
          that would cause it to get thrown before the service has started.

          The service is created in your Program.cs file (assuming you're using Visual
          Studio), I'd start looking in there first. Also check your service class for
          any static variables or class variables that are being set as the class is
          being instantiated.

          "Morten Wennevik [C# MVP]" <MortenWennevik @hotmail.comwro te in message
          news:BE2C9C37-C859-4F85-B647-FE1F739A209A@mi crosoft.com...
          Hi Jason,
          >
          No, errors in the configuration files are thrown by .Net Framework before
          the application is loaded. If this is a common issue, consider using a
          separate configuration file and load it manually.
          >
          --
          Happy Coding!
          Morten Wennevik [C# MVP]
          >
          >
          "Jason Richmeier" wrote:
          >
          >Is there a way to catch an application configuration error on startup?
          >>
          >I have written a windows service. If there is an error in the
          >configuratio n
          >file (such as invalid xml) the exception is thrown before the OnStart
          >method
          >is invoked. Is there a way to catch this exception?
          >>
          >Thank you,
          >>
          >Jason Richmeier

          Comment

          Working...