My Windows Service crashes with "the key does not exist in the appSettings configuration section"
There is the same question listed under The key 'UserID' does not exist in the appSettings configuration section, but unfortunately none of the answers worked in my case. All was working fine, I checked everything in and when I o开发者_如何学编程pened the solution again, it started crashing on the above. I cannot find any hint of what I am doing wrong. Any ideas?
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="SMS.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77b444444e089" requirePermission="false" />
</sectionGroup>
</configSections>
<appSettings>
<add key="URI" value="http://123.123.123.57:8080/smsxml/collector"/>
<add key="Provider" value="220"/>
<add key="LongCode" value="+3"/>
<add key="DBServer" value="APPS"/>
<add key="DBUsername" value="sms"/>
<add key="DBPassword" value="sms1"/>
<add key="Database" value="SMSService"/>
<add key="Pooling" value="True"/>
<add key="PoolMax" value="50"/>
<add key="PoolInit" value="5"/>
<add key="DBPollInterval" value="5"/>
</appSettings>
System.InvalidOperationException was unhandled
Message="The key 'LongCode' does not exist in the appSettings configuration section."
Source="System"
StackTrace:
at System.Configuration.AppSettingsReader.GetValue(String key, Type type)
at SMS.smsOxy..ctor() in C:\Documents and Settings\K\My Documents\Visual Studio 2008\Projects\SMSComponent-Oxy\SMSComponent\smsOxy.vb:line 327
at SMS.smsOxy.Main() in C:\Documents and Settings\K\My Documents\Visual Studio 2008\Projects\SMSComponent-Oxy\SMSComponent\smsOxy.vb:line 57
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at System.Activator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
" at System.Configuration.AppSettingsReader.GetValue(String key, Type type) at SMS.smsOxy..ctor() in C:\Documents and Settings\K\My Documents\Visual Studio 2008\Projects\SMSComponent-Oxy\SMSComponent\smsOxy.vb:line 327 at SMS.smsOxy.Main() in C:\Documents and Settings\K\My Documents\Visual Studio 2008\Projects\SMSComponent-Oxy\SMSComponent\smsOxy.vb:line 57 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel) at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData) at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext) at System.Activator.CreateInstance(ActivationContext activationContext) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()"
How are you starting your service? Make sure that appname.exe.config file in the folder where you are running service from has same appSettings.
Try to copy the <appSettings></appSettings>
from the app.config to the bin/Debug/appname.exe.config file as when one builds/compiles, VS.NET copies and renames app.config (to bin/Debug/appname.exe.config) over to the bin folder.
精彩评论