Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 108825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:58:23+00:00 2026-05-11T01:58:23+00:00

I have a windows service that has a custom configuration section. In the configSectionHandler

  • 0

I have a windows service that has a custom configuration section. In the configSectionHandler class I am using attributes on the properties to validate the settings like this:

    //ProcessingSleepTime Property     [ConfigurationProperty('ProcessingSleepTime', DefaultValue = 1000, IsRequired = false)]     [IntegerValidator(MinValue = 5, MaxValue = 60000)]     public Int32 ProcessingSleepTime     {         get         {             if (this['ProcessingSleepTime'] == null)                 return 100;              return (Int32)this['ProcessingSleepTime'];         }         set         {             this['ProcessingSleepTime'] = value;         }     } 

If a value in the configuration file fails validation, a ConfigurationErrorsException is thrown. In a windows service this happens as it is trying to start and it’s really ugly (it offers to launch the debugger). How can I gracefully handle this error? I tried wrapping the OnStart method in a try/catch but it had no effect.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:58:23+00:00Added an answer on May 11, 2026 at 1:58 am

    Or better yet (as you might need multiple such a properties), using the code from @Ricardo Villiamil, create:

    int GetIntFromConfigSetting(string settingName, int defaultValue) {    int retValue = defaultValue;    if(this.ContainsKey(settingName))    {       int sleepInterval;       if(Int32.TryParse(this[settingName], out sleepInterval)       {          retValue = sleepInterval;       }    }    return retValue; } 

    Then use it from any property you need to.

    EDIT: actually, after re-reading the question once more, looks like this solves your problem only half-way, as if the value is out of the defined range, it will throw exception anyway.

    EDIT2: You can hook the AppDomain.UnhandledException event in the static ctor of your config section handler. The static ctor is ran before any instance or static member of a class are accessed, so it guarantees that you will intercept the exception even if the main method of your service is not yet called.

    And then, when you intercept and log the error, you can exit the service with some error code != 0 ( Environment.Exit(errorCode) ), so the service manager knows it failed, but not try to invoke a debugger.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer $("input[type='text'][value!=0], option:selected[value!=0]"). closest("table").show().siblings("legend").addClass("highlighted"). find("img").attr("src", minus_path); is how I would (break… May 11, 2026 at 11:37 pm
  • Editorial Team
    Editorial Team added an answer Change your signature to accept a string. Then check if… May 11, 2026 at 11:37 pm
  • Editorial Team
    Editorial Team added an answer I'd say that the workflow of sign up, get e-mail,… May 11, 2026 at 11:37 pm

Related Questions

In a WCF service, I have two classes with the [DataContract] attribute. One of
Our company is nearing its go live date (and its getting a QA department
I have a windows service that runs fine, but I have to have it
I have a WCF service that is using a custom ServiceAuthorizationManager . The custom

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.