3

I am using EF 6.1.3 with MYSQL 5.6.12 server.I can run and use EF find and generate Data Model and has the required steps in application configuration file, whenever I try to generate views we get the following error ,can anyone give pointers on how to fix this?

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Data.Entity.Core.MetadataException: Schema specified is not valid. Errors: 
BitDatabaseModel.edmx(7,8) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
   at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader.ThrowOnNonWarningErrors()
   at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader.LoadItems(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths)
   at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, Boolean throwOnError, IDbDependencyResolver resolver)
   at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Init(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths, Boolean throwOnError, IDbDependencyResolver resolver, DbProviderManifest& providerManifest, DbProviderFactory& providerFactory, String& providerInvariantName, String& providerManifestToken, Memoizer`2& cachedCTypeFunction)
   at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection..ctor(IEnumerable`1 xmlReaders)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at Microsoft.DbContextPackage.Utilities.EdmxUtility.GetMappingCollectionEF6(Assembly ef6Assembly, String& containerName)
   at Microsoft.DbContextPackage.Handlers.OptimizeContextHandler.OptimizeEdmx(String inputPath)

App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <!--defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"-->
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <clear/>
      <!--The clear tag must be before the provider you want to use-->
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>
      </providers>
  </entityFramework>
  <connectionStrings>
    <add name="BitDatabaseEntities" connectionString="metadata=res://*/BitDatabaseModel.csdl|res://*/BitDatabaseModel.ssdl|res://*/BitDatabaseModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=username;user id=username;password=password;persistsecurityinfo=True;database=aci_dev&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.8.8.0" newVersion="6.8.8.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
<system.data>
    <DbProviderFactories>
      <remove name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" />
      <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.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data></configuration>

web.config

  <entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    </providers>
  </entityFramework>

Screenshot of dlls:

enter image description here

user3508811
  • 847
  • 4
  • 19
  • 43
  • Probably a duplicate of http://stackoverflow.com/questions/18455747/no-entity-framework-provider-found-for-the-ado-net-provider-with-invariant-name Have you installed the ADO.net provider for MySql.Data.MySqlClient? – Stefano Balzarotti Mar 03 '17 at 23:55
  • where/how to check if ADO.net provider is installed or not? – user3508811 Mar 04 '17 at 00:13
  • Check this: http://stackoverflow.com/a/42542277/5081328 – Stefano Balzarotti Mar 04 '17 at 17:45
  • I already have that...I get this error while generating views ,regular compilation works fine – user3508811 Mar 05 '17 at 01:37
  • What is the code you are using to generate the view? – Marcus Mar 05 '17 at 01:50
  • 3
    Haven't you already asked exactly the same question, and gave the answer by yourself [here](http://stackoverflow.com/questions/42472054/no-entity-framework-provider-found-for-the-ado-net-provider-with-invariant-name). – CodeFuller Mar 05 '17 at 05:31
  • @Marc - I am using `Entity Framework Power Tools for VS2013`,Right-click in .edmx file-->Entity framework menu-->Generate views,can you provide guidance? – user3508811 Mar 06 '17 at 02:42
  • 2
    @CodeFuller - the question was for unable to compile the code,here I am trying to generate the views with the procedure mentioned in the previous comment,can you help?am running into the problem as in http://stackoverflow.com/questions/25626880/entity-framework-powertools-generating-views-with-mysql-and-ef6 – user3508811 Mar 06 '17 at 02:43
  • @user3508811 what version of power tools are you using? Perhaps you could try reinstalling them. – Marcus Mar 06 '17 at 02:45

3 Answers3

0

What about reinstalling the ef power tools. Make sure you have the latest release as well.


Update: If this does not correct the binding references update the versions to the versions that your project requires.

Remove Entity Framework 6.0 and as a result the depending MySQL adapters with NuGet. Then, make sure to ONLY add the MySQL.Data.Entities, as all relevant depending assemblies are added automatically.

Marcus
  • 453
  • 3
  • 10
  • I did try reinstalling the latest version,removing my EF and installing MySQL.Data.Entities and only its dependencies – user3508811 Mar 06 '17 at 19:08
0

I noticed your binding redirect of the package is only to 6.8.8.0 Try increasing the version number to include a more recent version.

Marcus
  • 453
  • 3
  • 10
0

You must check your machine config to be sure it does not have an empty value. If it does, paste in your code to fix it in the machine config for your target framework.

    <system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <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.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>

Plus your connection string should use this providerName....

<add name="ftw" connectionString="xxx" providerName="MySql.Data.MySqlClient" />