10

I have a C# application with multiple project referenced. One of the project is referencing Microsoft.SqlServer.Types (Version 11), because it is using SQLGeometry. When i install my application to an empty computer (Only windows 7 with VC++ 2010) i get an error in my application, that it "

Could not load file or assembly 'Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies.

Any ideas why it would require Version 10?

JNM
  • 1,175
  • 4
  • 20
  • 39

2 Answers2

22

Please refer to this answer. You need to do one of the following:

  1. Add the Type System Version=SQL Server 2012 keyword to your connection string in app.config:

<configuration> <connectionStrings> <add name="YourConnectionStringName" connectionString="(connection string values);Type System Version=SQL Server 2012" /> </connectionStrings> </configuration>

  1. Add a bindingRedirect for Microsoft.SqlServer.Types in app.config:

<configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>

Either option will ensure that SqlConnection will load version 11.0.0.0 of the Microsoft.SqlServer.Types assembly, instead of version 10.0.0.0.

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
  • There's also a chance that you don't have version 11 installed on your computer. In that case, you'll also have to download the 2012 SQL feature pack: https://www.microsoft.com/en-us/download/details.aspx?id=29065 – Byte11 Jul 19 '18 at 15:33
  • 3
    For later versions, use NuGet package `` (and see ReadMe.htm installed as part of package to see actions required to load native assemblies at runtime). And the binding redirect ` ` – user3085342 Nov 03 '18 at 01:10
2

Somewhere in your solution a project (csproj file) or the web/app.config is still referencing version 10.0.0.0. Search solution wide for the string 10.0.0.0 and you will find the reference.

Chief Wiggum
  • 2,784
  • 2
  • 31
  • 44
  • Already tried that - found nothing. It seems that it tries to load assembly from GAC. Will try to set `SpecificVersion` to True. – JNM Nov 10 '14 at 06:31
  • Just to add to this answer, I was having this problem and traced the reference to a web.config file. I hadn't thought to look there since the class encountering the issue was part of a .dll file which had the correct reference (in a separate project). I guess I've got something to learn still because I'm not sure why the website reference would apply for the classes being instantiated from the .dll. – Ravendarksky Jan 27 '16 at 12:59