Serious problems with ConfigurationSettings class in a web service

B

Brad Wood

I have a 1.1 web service that creates multiple threads and makes an http
call within each thread. When many threads are created, the service
fails every on other call with one of these 2 errors:

(1) Parser Error Message: </b>The XML file
c:\windows\microsoft.net\framework\v1.1.4322\Config\machine.config could
not be loaded. Attempted to access an unloaded AppDomain.
(2) Parser Error Message: </b>The XML file
c:\windows\microsoft.net\framework\v1.1.4322\Config\machine.config could
not be loaded. [Resource lookup failed - infinite recursion detected.
Resource name: Arg_AppDomainUnloadedException]

When I comment out my http call block, e.g.,
using(HttpWebResponse response = http.GetResponse() as HttpWebResponse)
{
...
}
The service does not fail (as I would expect).

However, when I leave the http call in and comment out three earlier
lines that access config constants, e.g.,
string s = ConfigurationSettings.AppSettings.Get(1);
The service does not fail either.

What's even crazier is that the service takes 10X longer with the calls
to ConfigurationSettings.AppSettings (I suppose because there is some
conflict between the threads). The NameValueCollection base class
underlying the AppSettings collection says that static members of this
type are thread-safe (which AppSettings is).

Why is the ConfigurationSettings class seeming to be so hosed up here?
 
E

Emul

I've had similar problems in the past, so I always load the
ConfigurationSettings one-time only, and this seems to fix the problem.
I did not respond right away because I, too, was waiting for a
moderator/VIP to answer. But until and unless that happens, try
this...
// these must be static...
static bool GotSettings = false;
static string SomeSetting;
// your regular ctor loads those statics...
MyClass() // ctor
{
...
if(!GotSettings)
{
SomeSetting = ConfigurationSettings.AppSettings.Get(...);
GotSettings = true;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top