|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How do I use ConfigurationSettings.AppSettings collection safely from a thread?I've isolated a call to ConfigurationSettings.AppSettings.Get as the
source of an error in my application. The 1.1 documentation for both the ConfigurationSettings class and the NameValueCollection base class underlying the AppSettings collection say that all static members (which I am calling) are thread safe. What am I missing about accessing ConfigurationSettings from threads? Brad Wood wrote:
> I've isolated a call to ConfigurationSettings.AppSettings.Get as the What error are you getting?> source of an error in my application. > > The 1.1 documentation for both the ConfigurationSettings class and the Yes, but AppSettings returns an instance of a NameValueCollection. Get> NameValueCollection base class underlying the AppSettings collection say > that all static members (which I am calling) are thread safe. > is an instance method of the NameValueCollection. The documentation specifically says instance members on the NameValueCollection are not thread-safe. I didn't see anything that said the collection can support multple readers either. So technically that means you need to synchronize access to the AppSettings object everytime you need to read a configuration setting. Now, I suspect it's very likely that the NameValueCollection does indeed support multiple readers because the documentation also states that the underlying structure used is the Hashtable which does support multiple readers. The documentation should have been more clear though. > What am I missing about accessing ConfigurationSettings from threads? Like I said, ConfigurationSettings.AppSettings likely supports multiplereaders so you shouldn't have a problem. What makes you think the source of the error is with ConfigurationSettings? Brian Brian Gideon wrote:
> What error are you getting? It's in a web service; I get an error accessing the machine.config, "Attempted to access an unloaded AppDomain" or "Resource lookup failed - infinite recursion detected". This I assume due to a deadlock condition. > When I call ConfigurationSettings.AppSettings I get a static class. > >>The 1.1 documentation for both the ConfigurationSettings class and the >>NameValueCollection base class underlying the AppSettings collection say >>that all static members (which I am calling) are thread safe. >> > Yes, but AppSettings returns an instance of a NameValueCollection. Get > is an instance method of the NameValueCollection. Then when I call Get, an instance of NameValueCollection returns? > Like I said, ConfigurationSettings.AppSettings likely supports multiple Because the problem is consistent; when I replace all calls to > readers so you shouldn't have a problem. What makes you think the > source of the error is with ConfigurationSettings? ConfigurationSettings.AppSettings.Get with hard coded strings, no problems... Brad Wood wrote:
> Brian Gideon wrote: Hmm...I don't know. It doesn't sound like a deadlock condition to me.> It's in a web service; I get an error accessing the machine.config, > "Attempted to access an unloaded AppDomain" or "Resource lookup failed - > infinite recursion detected". This I assume due to a deadlock condition. > Can you post the stack trace of each exception? > > Yes, but AppSettings returns an instance of a NameValueCollection. Get AppSettings is a static property on the ConfigurationSettings class.> > is an instance method of the NameValueCollection. > > When I call ConfigurationSettings.AppSettings I get a static class. > Then when I call Get, an instance of NameValueCollection returns? > It returns an instance of the NameValueCollection class. Get is an instance method of that class. > > Like I said, ConfigurationSettings.AppSettings likely supports multiple Interesting. I'll be honest. I really don't know what the problem is,> > readers so you shouldn't have a problem. What makes you think the > > source of the error is with ConfigurationSettings? > > Because the problem is consistent; when I replace all calls to > ConfigurationSettings.AppSettings.Get with hard coded strings, no > problems... but it doesn't sound like a threading problem to me. Brian Gideon wrote:
> Hmm...I don't know. It doesn't sound like a deadlock condition to me. Both traces are the same except that the exception messege (same > Can you post the stack trace of each exception? exception) of the other one is: [Resource lookup failed - infinite recursion detected. Resource name: Arg_AppDomainUnloadedException] <Trace> [AppDomainUnloadedException]: Attempted to access an unloaded AppDomain. at System.Threading.Thread.SetCompressedStackInternal(IntPtr unmanagedCompressedStack) at System.Threading.Thread.SetCompressedStack(CompressedStack stack) at System.Xml.XmlTextReader.CreateScanner() at System.Xml.XmlTextReader.Init() at System.Xml.XmlTextReader.Read() at System.Xml.XmlReader.MoveToContent() at System.Web.Configuration.XmlUtil.OpenXmlTextReader() at System.Web.Configuration.HttpConfigurationRecord..ctor(String filename, HttpConfigurationRecord parent, Boolean inheritable, String path, String mappedPhysicalPath) [ConfigurationException]: The XML file c:\windows\microsoft.net\framework\v1.1.4322\Config\machine.config could not be loaded. Attempted to access an unloaded AppDomain. (c:\windows\microsoft.net\framework\v1.1.4322\Config\machine.config) at System.Web.Configuration.HttpConfigurationSystem.CacheLookup(String vpath) at System.Web.Configuration.HttpConfigurationSystem.ComposeConfig(String reqPath, IHttpMapPath configmap) at System.Web.HttpContext.GetCompleteConfigRecord(String reqpath, IHttpMapPath configmap) at System.Web.HttpContext.GetCompleteConfig(String path) at System.Web.HttpContext.GetConfig(String name, String path) at System.Web.HttpContext.GetMachineConfig(String name) at System.Web.HttpContext.GetAppLKGConfig(String name) </Trace> |
|||||||||||||||||||||||