1

I have 2 projects in my solution:

  1. An ASP.NET Core 2.2 Web API project
  2. A .net framework class library

In my class library I have created my entities using a database-first approach. In my Web API project, I am referencing the class library.

When I run the application, an exception gets thrown at this point:

return entities.IP_Types.ToList();

This is the exception below:

System.ArgumentException: 'The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.'

My app.config file seems to be correctly set up. I have the following code in it:

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
        <provider invariantName="System.Data.SqlClient" 
                  type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
</entityFramework>
0

2 Answers 2

1

I managed to get over the exception by adding this line to the Program's Main method:

DbProviderFactories.RegisterFactory("System.Data.SqlClient", SqlClientFactory.Instance);

Sign up to request clarification or add additional context in comments.

Comments

0

Check your database connection string. Either its missing the providerName or the config file is missing the settings for entityFramework provider.

<entityFramework>
    <providers>
        <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
</entityFramework>

To know more about the connection configuration, Check out EF Database Providers

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.