1

We upgraded a .Net Framework 4.5 project to .Net Framework 4.8 and some new things showed up in our app.config-file.

Is the code below (from app.config) necessary for MySQL and EntityFramework etc to work correctly?

Also, is it possible to accomplish the same thing as the code below programmatically, so that we can get rid of the app.config dependency?

We've tried to just remove the code below, but that resulted in our service not being able to start.

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    </providers>
  </entityFramework>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
  </startup>
  <system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory,MySql.Data" />
    </DbProviderFactories>
  </system.data>
  <system.web>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=<PUBLICKEY>" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=<PUBLICKEY>" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>

lormiz
  • 83
  • 6

1 Answers1

2

For the EntityFramework

There is a specific guide on Microsoft documentations stating that from EF6 onwards it can be done. Check here

Effectively the steps are the following:

  1. Create only one DbConfiguration class for your application. This class specifies app-domain wide settings.
  2. Place your DbConfiguration class in the same assembly as your DbContext class. (See the Moving DbConfiguration section if you want to change this.)
  3. Give your DbConfiguration class a public parameterless constructor.
  4. Set configuration options by calling protected DbConfiguration methods from within this constructor.

Example:

[DbConfigurationType(typeof(MyDbConfiguration))]
public class MyContextContext : DbContext
{
}

For the supported runtime

This has already been covered:

What happens if I remove the auto added supportedRuntime element?

Athanasios Kataras
  • 25,191
  • 4
  • 32
  • 61