None of the factories in the list of 'Devart.Data.MySql' were found.

Posts   
 
    
JanRHansen
User
Posts: 37
Joined: 02-Jan-2019
# Posted on: 27-Dec-2019 12:37:10   

Hi

So, I have a web application using an old Telerik ORM setup and a MySQL database, and I want to replace it with LLBLGen. I've never really used LLBLGen before, so "virgin territory" here...

I have done a Database first model and created source code (adapter templates) and when I try to do a very simple query;

        System.Diagnostics.Trace.TraceInformation("messaage here");
        System.Diagnostics.Trace.Flush();
        var products = new EntityCollection<ProductEntity>();

        using (var adapter = new DataAccessAdapter(connectionString))
        {
            var qf = new QueryFactory();
            var q = qf.Product.Where(ProductFields.Productid > -1);
            adapter.FetchQuery(q, products);
        }

        foreach (var productEntity in products)
        {
            uiTest.Text += $@"{productEntity.Description}<br/>";
        }
        System.Diagnostics.Trace.Flush();

I get this error:

System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'SD.LLBLGen.Pro.DQE.MySql.DynamicQueryEngine' threw an exception. Source=SD.LLBLGen.Pro.DQE.MySql StackTrace: at SD.LLBLGen.Pro.DQE.MySql.DynamicQueryEngine..ctor() at NHL.Admin.DataModel.DatabaseSpecific.DataAccessAdapter.CreateDynamicQueryEngine() in D:\projects\NHL\nhladmin\NHL.Admin.DataModel\DatabaseSpecific\DataAccessAdapter.cs:line 85 at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterCore.get_FunctionMappings() at SD.LLBLGen.Pro.QuerySpec.Adapter.AdapterExtensionMethods.FetchQuery[TCollection](IDataAccessAdapter adapter, IEntityQueryInternal query, TCollection collectionToFill) at SD.LLBLGen.Pro.QuerySpec.Adapter.AdapterExtensionMethods.FetchQuery[TEntity,TCollection](IDataAccessAdapter adapter, EntityQuery`1 query, TCollection collectionToFill) at NHL.Administration.AdminWebsite.ProductsOverview.Page_Load(Object sender, EventArgs e) in D:\projects\NHL\nhladmin\NHL.Administration.AdminWebsite\ProductsOverview.aspx.cs:line 27

Inner Exception 1: ORMGeneralOperationException: None of the factories in the list of 'Devart.Data.MySql' were found. Please check machine.config and the .NET version your application is running on.

I have added trace configuration in web.config: <system.diagnostics> <switches> <add name="MySqlDQE" value="4" /> <add name="ORMGeneral" value="4" /> <add name="ORMQueryExecution" value="4" /> <add name="ORMStateManagement" value="4" /> <add name="ORMPersistenceExecution" value="4" /> <add name="ORMPlainSQLQueryExecution" value="4" /> <add name="LinqExpressionHandler" value="4" /> </switches>

<trace autoflush="false" indentsize="4">
  <listeners>
    <add name="myListener" type="System.Diagnostics.TextWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" initializeData="TextWriterOutput.log" />
    <!--<remove name="Default" />-->
  </listeners>
</trace>

</system.diagnostics>

But I only get the "message here" test trace message in the file - so I don't think that LLBLGen emits anything further, when this exception occurs.

So the question is - why does this happen?

A partial solution:

I have discovered that we have previously entered this in web.config

<system.data> <DbProviderFactories> <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>

According to commit messages (2 years ago), this was needed to get our build server to build the project. I don't know why simple_smile

If I remove the DbProviderFactories section from web.config, the code runs fine (and emits a ton of tracemessages btw, so that part is configured correctly)

In machine.config I have this:

<DbProviderFactories>
  <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient"
    description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.6.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  <add name="dotConnect for MySQL" invariant="Devart.Data.MySql"
    description="Devart dotConnect for MySQL" type="Devart.Data.MySql.MySqlProviderFactory, Devart.Data.MySql, Version=8.16.1541.0, Culture=neutral, PublicKeyToken=09af7300eec23701" />
</DbProviderFactories>

The problem is that we apparently need that part of web.config for builds to run - so I'm not sure if I can safely delete it.

I have tried to add the second one (<add name="dotConnect for MySQL" invariant="Devart.Data.MySql"...>) from machine.config to web.config, but that doesn't change anything.

I'm kind of lost here - probably because I don't fully understand the purpose of the DbProviderFactories section of machine.config / web.config. I thought web.config would overwrite the specifics from machine.config, but in that case it shouldn't matter if I repeat machine.config values in web.config.

Any ideas/insights as to what is actually going on?

Thanks in advance!

Details: MySQL version 5.6.43 LLBLGen version 5.6 (5.6.1) RTM DevArt version (latest express from their website - 8.16 apparently) Asp.net web project targets .net version 4.6 Nuget packages: SD.LLBLGen.Pro.DQE.MySql - 5.6.1 SD.LLBLGen.Pro.ORMSupportClasses - 5.6.1 SD.LLBLGen.Pro.ORMSupportClasses.Web - 5.6.1

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 27-Dec-2019 14:31:14   

Try removing the DbProviderFactories in the web.config. And make sure the one in the machine.config, is in the machine.config that your application is targeting (32bit vs 64bit).

JanRHansen
User
Posts: 37
Joined: 02-Jan-2019
# Posted on: 27-Dec-2019 14:36:36   

Hi

Thanks for your answer simple_smile

Yeah... as I wrote:_ If I remove the DbProviderFactories section from web.config, the code runs fine_. So I already know that.

However, I'm not sure I can do that due to our build server setup.

Could you elaborate on the "And make sure the one in the machine.config, is in the machine.config that your application is targeting (32bit vs 64bit)." part?

Where do I look? Would it be redundant to have the same configuration in both machine.config and web.config? What is it there for? What does the error message from llblgen mean?

Best regards Jan

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 28-Dec-2019 09:12:25   

A factory can be defined in either the machine.config file or the app/web.config file of the application. If it's defined in the machine.config file, you first have to 'undefine' it in the app/web.config file (using the <remove invariantname=""> element, see '<DbProviderFactories>' documentation in Microsoft Docs). There are 2 machine.config files: one for 32bit .NET and one for 64bit .NET: c:\windows\Microsoft.NET\Framework\v4.0....\Config << 32bit c:\windows\Microsoft.NET\Framework64\v4.0....\Config << 64bit

So if you have an entry in the 64bit machine.config file, and your website runs as a 32bit application inside IIS, then the 32bit machine.config file will be read at runtime by DbProviderFactories (a .NET class) and not the 64bit one simple_smile

I think that's why you need the part in your web.config file, your webapp likely runs as 32bit (I think that's the default under some IIS versions, but not sure) and therefore a machine.config file without the right factory is used.

Frans Bouma | Lead developer LLBLGen Pro