I'm devoloping a windows service which requires a socket connection to my server to do its job. I made the service establish the connection through a thread that is started on the OnStart service's event. It worked until this morning when I've compiled it again after some changes I've made: it crashes on the initialization of the client variable. Here is the part of the code where it crashes:
Try
client = New TcpClient 'the error is here
client.Connect(ip, port)
stream = client.GetStream()
receiver.Start()
tryingconnect_thread.Abort()
Catch ex As Exception
File.WriteAllText("C:\error.txt", ex.Message) 'here it gives me "Configuration system failed to initialize"
System.Threading.Thread.Sleep(10000)
End Try
To be sure I also tried the Try Catch End Try statements only with the initialization in it. How can I solve this problem?
I've already seen other questions like this, but none of them worked.
EDIT:
This is the exception:
System.Configuration.ConfigurationErrorsException: Impossibile inizializzare il sistema di configurazione ---> System.Configuration.ConfigurationErrorsException: Sezione di configurazione authentication non riconosciuta. (C:\Users\Davide\Documents\Visual Studio 2013\Projects\winddsvc\winddsvc\bin\Debug\winddsvc.exe.Config line 8)
in System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
in System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
in System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
in System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
--- Fine della traccia dello stack dell'eccezione interna ---
in System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
in System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
in System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
in System.Configuration.ConfigurationManager.GetSection(String sectionName)
in System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
in System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
in System.Diagnostics.DiagnosticsConfiguration.Initialize()
in System.Diagnostics.DiagnosticsConfiguration.get_Sources()
in System.Diagnostics.TraceSource.Initialize()
in System.Net.Logging.InitializeLogging()
in System.Net.Logging.get_On()
in System.Net.Sockets.TcpClient..ctor(AddressFamily family)
in System.Net.Sockets.TcpClient..ctor()
in winddsvc.winddsvc.tryconnect() in C:\Users\Davide\Documents\Visual Studio 2013\Projects\winddsvc\winddsvc\Service1.vb:riga 88
And this is the config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<authentication mode="Windows" />
<identity impersonate="true" />
</configuration>
I've just found the solution: simply remove the
<authentication mode="Windows" />
<identity impersonate="true" />
part from the config file.