DbProviderFactories.GetFactoryClasses returns no results after installing .NET SQL Client in .NET Core 2.1

In .NET Framework, the providers are automatically available via machine.config and are also registered globally in the GAC. In .NET Core, there is no GAC or global configuration anymore. This means that you'll have to register your provider in your project first, like so:

using System.Collections.Generic;
using System.Data.CData.MySQL; // Add a reference to your provider and use it
using System.Data.Common;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            // Register the factory
            DbProviderFactories.RegisterFactory("test", MySQLProviderFactory.Instance);

            // Get the provider invariant names
            IEnumerable<string> invariants = DbProviderFactories.GetProviderInvariantNames(); // => 1 result; 'test'

            // Get a factory using that name
            DbProviderFactory factory = DbProviderFactories.GetFactory(invariants.FirstOrDefault());

            // Create a connection and set the connection string
            DbConnection connection = factory.CreateConnection();
            connection.ConnectionString = "Server = test, Database = test";
        }
    }
}

As you can see, I had to add a reference to my Provider, "System.Data.CData.MySQL" in this case.

It's sad that you can't just get all available providers anymore, but this is what we have to work with in .NET core.

(Information from this GitHub corefx issue)


As Amer mentioned before:

In .net core you have to register the Factory

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

However, to do this you should add the System.Data.SqlClient nuget package to your project.

Like this (Tools -> Nuget package manager -> Package Manager Console)

Find-Package SQLClient
Install-Package System.Data.SqlClient -ProjectName YourProjectName