Configuration Error - Unrecognized attribute '

2019-06-26 06:19发布

问题:

When trying to access my database in a live web application I get the error:

Server Error in '/' Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Unrecognized attribute 'name'.

Source Error:

An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Source File: C:\home\site\wwwroot\web.config Line: 115

My web config where line 115 is located:

<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" />
  <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
  <remove invariant="MySql.Data.MySqlClient" name="MySQL Data Provider" /> // Line: 115
  <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /></DbProviderFactories>
</system.data>

When I remove: name="MySQL Data Provider" from that line, I just get another error and go around in circles.

Also when I refresh the page and remove that name part I get:

Unable to find the requested .Net Framework Data Provider. It may not be installed.

Any help is greatly appreciated.

回答1:

I had a very similar problem and nothing was working for me. I fixed it by changing the .NET framework version to 4.5 instead of 4.5.2.Take a look at this article.



回答2:

After 8 hours I managed to solve this. For some reason, in NuGet Package Manager it said the version I had installed was Version=6.9.9.0 so I added:

<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />

to my web.config and yet it still didn't work, I tried everything, reinstalling, etc. etc. and then eventually I went into my bin folder and the actual version there was 6.8.3.0 yet NuGet displayed 6.9.9.0 - strange!

I deleted these from the bin folder and then reinstalled the latest version and it all worked!



回答3:

I think the name must not contains spaces and also you have two data providers with same name so your code should be like this:

<add name="MySQLDataProvider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  <add name="MySQLDataProvider2" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /></DbProviderFactories>