DbProviderFactory information for compatibilitylevel SqlServer2005 wasn't properly initialized

Posts   
 
    
MoGoMo
User
Posts: 6
Joined: 25-Jul-2022
# Posted on: 25-Jul-2022 00:37:12   

Hey all, I've been seeing a similar issue to this one https://www.llblgen.com/tinyforum/Thread/24505 when using LLBLGen.Pro.ORMSupportClasses 5.3.4/System.Data.SqlClient 4.4.0 in a new Console application targeting .NET 6.0 (the referenced projects for "DataAccessAdapter/LinqMetaData" are using .NET Framework 4.8 with the same package versions):

<snip>
using SD.LLBLGen.Pro.DQE.SqlServer;
using SD.LLBLGen.Pro.ORMSupportClasses;

Console.WriteLine("Hello world!");

var _adapter = new DataAccessAdapter("<snip>");
var _database = new LinqMetaData(_adapter);

RuntimeConfiguration.ConfigureDQE<SQLServerDQEConfiguration>(c => c.AddDbProviderFactory(typeof(System.Data.SqlClient.SqlClientFactory)));

Console.WriteLine(_database.Clientele
    .Where(c => c.ClientId == "<snip>")
    .FirstOrDefault());

Adding the suggested fix in the other thread still returns the same error, just on this newly added line instead of inside the DataAccessAdapter:

System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine' threw an exception.

This exception was originally thrown at this call stack: [External Code]

Inner Exception 1: ORMGeneralOperationException: DbProviderFactory information for compatibilitylevel SqlServer2005 wasn't properly initialized.

My understanding is that the referenced projects don't use a DbProviderFactory because that was added in .NET Core, does anyone here have an idea about how I can resolve this issue?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 25-Jul-2022 09:25:34   

You have to include the SqlClient nuget package in your app. This isn't done by .NET itself like it is done on .NET Fx. Have you done that?

Frans Bouma | Lead developer LLBLGen Pro
MoGoMo
User
Posts: 6
Joined: 25-Jul-2022
# Posted on: 25-Jul-2022 23:10:46   

I believe so, Microsoft.Data.SqlClient 4.0.1 and System.Data.SqlClient 4.4.0. I've tried these at a few different versions based on what I can see in the projects here, but the same error happens for all of them

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 26-Jul-2022 09:00:02   

Ah I think it might be the fact you place the runtimeconfiguration call below the adapter creation. Please perform the factory registration in runtimeconfiguration as early as possible.

Also, the callstack should give you the line where this call happens, is that in the query? We can't reproduce it so it must be something with the setup you have. If what I suggested above doesn't work, please attach a repro case which reproduces the issue so we can have a look.

Frans Bouma | Lead developer LLBLGen Pro
MoGoMo
User
Posts: 6
Joined: 25-Jul-2022
# Posted on: 08-Aug-2022 00:20:21   

We decided to finally update to the newest version of LLBLGen, as locally we could see that it fixed the issue, so likely this can be marked as solved. I'll also open a new thread (https://www.llblgen.com/tinyforum/Thread/27596) for an issue I found when running the tool as it creates some invalid code.