The static field 'Instance' of type 'Microsoft.Data.SqlClient.SqlClientFactory' is null and therefore this DbProviderFactory can't be used

Posts   
 
    
mjdearoz
User
Posts: 1
Joined: 24-Oct-2022
# Posted on: 24-Oct-2022 17:32:17   

Hi. I am running into a similar issue as this post https://www.llblgen.com/tinyforum/Thread/27042. I am currently trying to move from .Net Framework 4.7.2 to .Net Standard 2.0. I have included Microsoft.Data.SqlClient 5.0.1 in the project. I have also tried it with System.Data.SqlClient 4.8.4, but still getting the same error. I have tried the suggestions in the other thread, but no luck. Any other suggestions? Thanks

SD.LLBLGen.Pro.ORMSupportClasses.RuntimeConfiguration.ConfigureDQE<SD.LLBLGen.Pro.DQE.SqlServer.SQLServerDQEConfiguration>(
              c => c.AddDbProviderFactory(typeof(Microsoft.Data.SqlClient.SqlClientFactory)));
The following exception occurred at Void StoreDbProviderFactoryRegistration(System.Type, System.String):
The static field 'Instance' of type 'Microsoft.Data.SqlClient.SqlClientFactory' is null and therefore this DbProviderFactory can't be used.
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 25-Oct-2022 08:23:32   

The property 'Instance' is filled by the static ctor of the ADO.NET provider factory, so it runs when your app first runs. Not sure where you put the factory registration, but try to move it to a position that runs a little later in your application so you know the .net runtime has called the static ctors. (and that these indeed succeed. It might be the static constructors of the ado.net provider fail because of a misconfiguration which leads to things not being initialized). It's a weird issue tho, as you can see in the other thread you refer to...

Frans Bouma | Lead developer LLBLGen Pro