EFCache CachingProviderServices lacks static Instance property

2

I am attempting to use the EFCache NuGet package (https://github.com/moozzyk/EFCache) in a .NET 4.5 project, and running into this error on startup:

System.InvalidOperationException
HResult=0x80131509
Message=The Entity Framework provider type '
EFCache.CachingProviderServices, EFCache, Version=1.1.3.0, 
Culture=neutral, PublicKeyToken=46c4868af4307d2c' did not have a static 
property or field named 'Instance'. Entity Framework providers must 
declare a static property or field named 'Instance' that returns the 
singleton instance of the provider.

EFCache.CachingProviderServices extends System.Data.Entity.Core.Common.DbProviderServices, which does NOT have a static Instance property. So it seems that this property is not necessarily there in all cases.

Looking at the the code of EFCache.CachingProviderServices, I don't see any sensible way for it to have a static instance property, since its purpose is to serve as a wrapper around another DBProviderServices instance that is passed as a constructor argument.

Does anyone who's gotten EFCache to work with Entity Framework have any thoughts on what's going on?

EFCache version is 1.1.3.0. I've seen the same issue using Entity Framework 6.1.0 and 6.2.0. Web.config section looks like this:

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

c#
entity-framework-6
asked on Stack Overflow May 5, 2019 by Mike Kantor

1 Answer

2

The issue is caused by the following line in the config file:

<provider invariantName="MySql.Data.MySqlClient" type="EFCache.CachingProviderServices, EFCache" />

It's supposed to describe the actual db provider and for MySQL it usually looks like this:

<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.11.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />

In general, as described in the linked page, EFCache.CachingProviderServices is a wrapping provider, hence it's not supposed to (and can't) be registered as a regular database provider (which requires them to provide the static Instance property/field mentioned in the exception).

Instead, it has to be activated via custom DbConfiguration or static EntityFrameworkCache.Initialize() method as explained in How to use it.

answered on Stack Overflow May 5, 2019 by Ivan Stoev

User contributions licensed under CC BY-SA 3.0