tumtumtum / Shaolinq

ORM for .NET with full LINQ support for Postgres, Sqlite, MySql and SqlServer
Other
127 stars 19 forks source link

MySqlException "Invalid attempt to Read when reader is closed." #85

Closed thomasw-mitutoyo-ctl closed 6 years ago

thomasw-mitutoyo-ctl commented 6 years ago

I have some fairly simple database and some fairly simple code (IMHO). When I run it, I always get a MySqlException "Invalid attempt to Read when reader is closed."

It happens with or without scope. It happens with ToList() and ToListAsync().

    using (var scope = new DataAccessScope())
    {
        var configuration = MySqlConfiguration.Create("...", "localhost", "...", "...");
        using (var model = DataAccessModel.BuildDataAccessModel<MyModel>(configuration))
        {
            List<Mitarbeiter> results = model.Mitarbeiter.ToList(); // <-- exception here
            foreach (var result in results)
            {
                Console.WriteLine(result.Vorname);
            }
        }
    }

I am working with the Nuget packages Shaolinq.MySql 1.3.1.1208. Shaolinq 1.3.1.1208 Platform.Xml.Serialization 1.2.1.291 Platform.NET 1.2.1.291 MySql.Data 6.10.5

tumtumtum commented 6 years ago

Hi Thomas. That is very simple code and should work. Are you able to provide a simple project that I can compile and run on my end? It's possible that there's some authentication issues though you should have gotten a more specific exception.

thomasw-mitutoyo-ctl commented 6 years ago

I don't think there should be authentication issues. I have implemented the same query using plain MySql.Data methods and it works. I have even referenced the password and user information from that code.

I have sent you the complete source code (almost MCVE: plain MySql.Data implementation + Shaolinq) via email. I'm using VS 2015 Enterprise and the solution is targeting .NET 4.5.2

tumtumtum commented 6 years ago

This appears to be a problem introduced with MySql 6.10.5. For now, could you try downgrading to MySql 6.9.10? I'll look into what's changed.

thomasw-mitutoyo-ctl commented 6 years ago

Unfortunately, downgrading to 6.9.10 resulted in a version conflict. I got a FileLoadException, which can be bypassed by removing the following assembly redirection in the app.config:

  <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.10.5.0" newVersion="6.10.5.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
tumtumtum commented 6 years ago

I've pushed out a fix in Shaolinq version 1.3.1.1240. It should be available on NuGet momentarily. Let me know if it solves it for you.

thomasw-mitutoyo-ctl commented 6 years ago

Thanks, the new version seems ok. I had to re-enable above assembly redirection and it works again.