Error starting WPF application

Asked

Viewed 269 times

2

When starting my application, an error message is displayed. The problem is that I cannot locate the source of the problem. Before I couldn’t, it started today. I thought it might be some configuration, but I didn’t change anything in Visual Studio, as I remember. Visual Use 2017 (English) and WPF. See the error image below:

inserir a descrição da imagem aqui

Here is my App.Config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="inetConn" connectionString="Data Source=NOTEBOOK\Instancia; Initial Catalog=SILOS; User Id=sa; Password=@d123" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>
  • how is your config ?

  • @Rovannlinhalis, I will post my App.Config in the post edition.

  • 1

    in one of the errors, says that configSections should be the first child, within the Configuration node. I think you can start to solve it there

1 answer

1

The Exception says:

Configurationerrorsexception: Only one element is allowed per configuration file and, if present, must be the first child of the element

Update if config by placing <configSections> before <connectionStrings>, being like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
   <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="inetConn" connectionString="Data Source=NOTEBOOK\Instancia; Initial Catalog=SILOS; User Id=sa; Password=@d123" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>
  • If you press the stop button it will stop and when I give F5 again, comes the problem. If you have problem I know, but design does not have, soon this problem appears when I rotate and the message does not tell me where is the source of the problem, as I said in the post.

  • Ahhhh, got it ! Now I get it, I’m going to look for the solution.

  • Put the code where you have the <configSections> for us to see, it probably has double tags.

  • I didn’t know this, but as I put the Trings connectioStrings in front of the configSections, it didn’t work. I switched and it worked. I didn’t know that.

  • Ahhh, I just edited and you replied hahaha. But good at least solved !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.