title: Internal LazyIinternalConnection error with Mono
body: <p>I have an error with a MySql database console app that <em>must</em> run on mono. On microsoft's .NET it is running flawlessly but on Mono 2.11.4 it just won't work. </p>
  
  <p>I have already tried setting most of the "Copy Local" settings of the reference to "true", but to no avail.</p>
  
  <p>At the beginning of the application I immediately get the following exception:</p>
  
  <pre><code>Unhandled Exception:
  
  System.TypeInitializationException: An exception was thrown by the type initializer for System.Data.Entity.ModelConfiguration.Utilities.TypeExtensions ---&gt; System.InvalidProgramException: Invalid IL c
  ode in System.Data.Metadata.Edm.PrimitiveType:GetEdmPrimitiveTypes (): method body is empty.
  
    at System.Data.Entity.ModelConfiguration.Utilities.TypeExtensions..cctor () [0x00000] in &lt;filename unknown&gt;:0
    --- End of inner exception stack trace ---
    at System.Data.Entity.Internal.DbSetDiscoveryService.GetSets () [0x00000] in &lt;filename unknown&gt;:0
    at System.Data.Entity.Internal.DbSetDiscoveryService.InitializeSets () [0x00000] in &lt;filename unknown&gt;:0
    at System.Data.Entity.DbContext.DiscoverAndInitializeSets () [0x00000] in &lt;filename unknown&gt;:0
    at System.Data.Entity.DbContext.InitializeLazyInternalContext (IInternalConnection internalConnection, System.Data.Entity.Infrastructure.DbCompiledModel model) [0x00000] in &lt;filename unknown&gt;:0
    at System.Data.Entity.DbContext..ctor (System.String nameOrConnectionString) [0x00000] in &lt;filename unknown&gt;:0
    at oldforum2vanille.NewForum.vforumEntities1..ctor () [0x00000] in &lt;filename unknown&gt;:0
    at oldforum2vanille.Program.ConvertDiscissionTopics (Int32 newforumid, System.String forumtitle) [0x00000] in &lt;filename unknown&gt;:0
    at oldforum2vanille.Program.Main (System.String[] args) [0x00000] in &lt;filename unknown&gt;:0
  [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for System.Data.Entity.ModelConfiguration.Utilities.TypeExtensions ---&gt; System.In
  validProgramException: Invalid IL code in System.Data.Metadata.Edm.PrimitiveType:GetEdmPrimitiveTypes (): method body is empty.
  
    at System.Data.Entity.ModelConfiguration.Utilities.TypeExtensions..cctor () [0x00000] in &lt;filename unknown&gt;:0
    --- End of inner exception stack trace ---
    at System.Data.Entity.Internal.DbSetDiscoveryService.GetSets () [0x00000] in &lt;filename unknown&gt;:0
    at System.Data.Entity.Internal.DbSetDiscoveryService.InitializeSets () [0x00000] in &lt;filename unknown&gt;:0
    at System.Data.Entity.DbContext.DiscoverAndInitializeSets () [0x00000] in &lt;filename unknown&gt;:0
    at System.Data.Entity.DbContext.InitializeLazyInternalContext (IInternalConnection internalConnection, System.Data.Entity.Infrastructure.DbCompiledModel model) [0x00000] in &lt;filename unknown&gt;:0
    at System.Data.Entity.DbContext..ctor (System.String nameOrConnectionString) [0x00000] in &lt;filename unknown&gt;:0
    at oldforum2vanille.NewForum.vforumEntities1..ctor () [0x00000] in &lt;filename unknown&gt;:0
    at oldforum2vanille.Program.ConvertDiscissionTopics (Int32 newforumid, System.String forumtitle) [0x00000] in &lt;filename unknown&gt;:0
    at oldforum2vanille.Program.Main (System.String[] args) [0x00000] in &lt;filename unknown&gt;:0
  </code></pre>
  
  <p>I have already tried a proposed solution at <a href="http://alpascual.com/post/2011/05/27/Error-Unable-to-find-the-requested-Net-Framework-Data-Provider-It-may-not-be-installed.aspx" rel="nofollow">http://alpascual.com/post/2011/05/27/Error-Unable-to-find-the-requested-Net-Framework-Data-Provider-It-may-not-be-installed.aspx</a> (because his error message is roughly equal) so I added these lines to my app.config</p>
  
  <pre><code>&lt;system.data&gt;
      &lt;DbProviderFactories&gt;
        &lt;remove invariant="MySql.Data" /&gt;
        &lt;add name="ADO.Net driver for MySQL" invariant="MySql.Data" description="ADO.Net driver for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data.MySqlClient, Version=6.6.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /&gt;
      &lt;/DbProviderFactories&gt;
  &lt;/system.data&gt;
  </code></pre>
  
  <p>After some fiddling with the configuration, the Entity Framework now again uses the MySql because of these lines, but Mono just skips this configuration and gives the above Unhandled Exception again. :(</p>
  
  <p>Any of you have an idea? Am I forgetting something?</p>