初始化新的TcpClient时出现“配置系统初始化失败”

达德克斯

我正在开发Windows服务,该服务需要与服务器的套接字连接才能完成其工作。我使服务通过在OnStart服务的事件上启动的线程建立连接。它一直工作到今天早上,在进行了一些更改之后我再次对其进行了编译:它在客户端变量的初始化时崩溃。这是代码崩溃的部分:

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

可以肯定的是,我也只在初始化的情况下尝试过Try Catch End Try语句。我怎么解决这个问题?

我已经看过其他类似的问题,但是没有一个起作用。

编辑:

这是例外:

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

这是配置文件:

<?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>
达德克斯

我刚刚找到了解决方案:只需删除

<authentication mode="Windows" />
<identity impersonate="true" />

部分来自配置文件。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章