jonwagner / Insight.Database

Fast, lightweight .NET micro-ORM
Other
857 stars 145 forks source link

After upgrade to 6.3.2: Could not load file or assembly 'Microsoft.Data.SqlClient, Version=1.10.19324.4 #449

Closed jeroenbu closed 3 years ago

jeroenbu commented 3 years ago

Hi,

I've been stumped by this one: I've upgraded from 6.2.11 to 6.3.2, via NuGet. I'm working on a .NET Framework (4.6.1) C# MVC app. Due to some changes in another dependency I was forced to update my SqlClient to from System.Data.SqlClient to the Microsoft.Data.SqlClient namespace. Following that, I decided to update Insight.Database to 6.3.2. However, when I do a QuerySQL (probably the first type of connection to my database) i get an error: "Could not load file or assembly 'Microsoft.Data.SqlClient, Version=1.10.19324.4" I have in my NuGet Microsoft.Data.SqlClient 2.0.1, can't find any other version on my system. I tried getting earlier versions of this client from NuGet, but the error stayed... Anyone got any clues how I could solve this one?

Thx,

Jeroen

jeroenbu commented 3 years ago

And perhaps an interesting tidbit: I normally use SqlInsightDbProvider.RegisterProvider(). I tried Insight.Database.Providers.SqlInsightDbProvider.SqlInsightDbProvider.RegisterProvider(), which does give me another error: Cannot derive parameters for the stored procedure spWithSomeCoolName, Have you loaded the provider that supports SqlCommand?

jeroenbu commented 3 years ago

Got a solution. Apparently was missing this in my web.config:

      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.SqlClient" publicKeyToken="23ec7fc2d6eaa4a5" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.20168.4" newVersion="2.0.20168.4" />
      </dependentAssembly>

Added this, and now my application starts.

jonwagner commented 3 years ago

For the RegisterProvider issue, see issue #441. I kinda messed that one up. :-/

Insight 6.3 certainly supports Microsoft.Data.SqlClient with Insight.Database.Providers.MsSqlClient. In 6.3, that's automatically pulled in with the main Insight.Database package. When you add that package, nuget should automatically include Microsoft.Data.SqlClient and resolve to the latest version of the library.

I updated the HelloWorld sample to run with Microsoft.Data.SqlClient v2.1 and everything seems to work well.

Give it a shot with 6.3.3 without the binding redirect and let me know how it goes.

It seems weird that you have to add the binding redirect. Please reopen this if you want me to look into it more.