Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I'm trying to build a project in C# using WPF as my front end and EntityFramework/MySql as my backed but I can't get my code to even make a connection to my DB.

The structure of my project is as follows:

  1. Models
  2. Data Layer Framework (Repository Interfaces, UnitOfWork interface, etc.)
  3. EntityFramework/MySql
  4. Services
  5. UI (I want my connection strings here)

I've installed the .NET connector from Oracle, and I've tried a bunch of different Nuget packages but whenever my code tries to do anything in the EntityFramework/MySq layer I get an exception.

Currently I have the following Nuget packages installed:

  1. Entity Framework
  2. MySql.Data
  3. MySql.Data.Entity

The app.config in my EntityFramework/MySq layer is as follows:

<?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>
    <entityFramework>
        <providers>
            <provider invariantName="MySql.Data.MySqlClient"
              type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity"/>
        </providers>
    </entityFramework>
    <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.9.8.0" newVersion="6.9.8.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
    <system.data>
        <DbProviderFactories>
            <remove invariant="MySql.Data.MySqlClient"></remove>
            <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.7.2.0"/>
        </DbProviderFactories>
    </system.data>
</configuration>

And the app.config in my UI layer is as follows:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <connectionStrings>
        <add name="VolunteerDb" connectionString="server=localhost;user id=root;password=mypass;database=mydb" providerName="MySql.Data.MySqlClient" />
    </connectionStrings>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
  <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.9.8.0" newVersion="6.9.8.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

And when I try to run and access the DB in my repository I get the following exception:

Additional information: Could not load file or assembly 'MySql.Data, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference

What do I need to do to get EntityFramework working with MySql? Any help on this would be appreciated!

Edit

Here's what the packages.config looks like:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="6.1.3" targetFramework="net45" />
  <package id="Google.ProtocolBuffers" version="2.4.1.555" targetFramework="net45" />
  <package id="MySql.Data" version="7.0.2-DMR" targetFramework="net45" />
  <package id="MySql.Data.Entity" version="7.0.2-DMR" targetFramework="net45" />
</packages>
share|improve this question
    
could you include your packages.config in your question? – chandler Jun 28 at 22:23

It looks like you might have the wrong version of MySql your packages/references. Try running this in Package Manager Console (Tools > Nuget Package Manager > Package Manager Console):

 Uninstall-Package MySql.Data

 Install-Package MySql.Data -version 6.9.8

PS: you might have to run Uninstall-Package MySql -force

share|improve this answer
    
@amura.cxg let me know if this doesn't work – chandler Jun 28 at 22:21
    
I'd seen a similar answer before but when I run Install-Package MySql -version 6.9.8 on my EntityFramework/MySql project, it gives me this error Install-Package : Unable to find version '6.9.8' of package 'MySql' – amura.cxg Jul 5 at 15:51
    
@amura.cxg sorry I forgot the '.Data' please look at the updated answer – chandler Jul 5 at 18:12
    
gave that a try, it installed this time but I still get the error. I wonder if my app.config is malformed after so trying so many things – amura.cxg Jul 5 at 21:28

Try to change the lines of your config files to:

<bindingRedirect oldVersion="0.0.0.0-6.7.2.0" newVersion="6.7.2.0" />
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.