Share via


Trying to read a value from SqlClient, getting Could not load file or assembly 'Microsoft.SqlServer.Types, Version=10.0.0.0

Question

Sunday, January 19, 2020 4:22 PM

My code is as follows:

string uniqueName = columnMetaData[i].UniqueName;
string shortName = columnMetaData[i].Name;
object value = reader.IsDBNull(i) ? null : reader.GetValue(i);

reader is a: {System.Data.SqlClient.SqlDataReader}

I get the exception:

System.IO.FileNotFoundException
  HResult=0x80070002
  Message=Could not load file or assembly 'Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
  Source=mscorlib
  StackTrace:
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
   at System.Data.SqlClient.SqlConnection.ResolveTypeAssembly(AssemblyName asmRef, Boolean throwOnError)
   at System.Data.SqlClient.SqlConnection.<>c__DisplayClass172_0.<CheckGetExtendedUDTInfo>b__0(AssemblyName asmRef)
   at System.TypeNameParser.ResolveAssembly(String asmName, Func`2 assemblyResolver, Boolean throwOnError, StackCrawlMark& stackMark)
   at System.TypeNameParser.ConstructType(Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
   at System.TypeNameParser.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
   at System.Type.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError)
   at System.Data.SqlClient.SqlConnection.CheckGetExtendedUDTInfo(SqlMetaDataPriv metaData, Boolean fThrow)
   at System.Data.SqlClient.SqlDataReader.GetValueFromSqlBufferInternal(SqlBuffer data, _SqlMetaData metaData)
   at System.Data.SqlClient.SqlDataReader.GetValueInternal(Int32 i)
   at System.Data.SqlClient.SqlDataReader.GetValue(Int32 i)
   at WindwardReportsDrivers.net.windward.datasource.ado.AdoResultSet.GetRowMap(DbDataReader reader) in C:\git\Jenova\engine\DotNetEngine\WindwardReportsDrivers\net\windward\datasource\ado\AdoResultSet.cs:line 92

I went to add Microsoft.SqlServer.Types via NuGet, but it only goes back to 10.50.

A couple of questions:

  1. Why is a request for a value from SqlServer requiring an NuGet package?
  2. Why is it requiring such an old version?
  3. Is there any way to make this work???

thanks - dave

What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

All replies (4)

Monday, January 20, 2020 7:34 AM ✅Answered

Hi DavidThi808,
First your target platform should be the .NET Framework. The.NET Core platform is not supported by Microsoft.SqlServer.Types.
By default, SqlClient uses version 10.0 of the Microsoft.SqlServer.Types assembly (even if you reference a newer version in your project). 
>>I went to add Microsoft.SqlServer.Types via NuGet, but it only goes back to 10.50.
You can add the Microsoft.SqlServer.Types by following the steps.
1.Right click the project>Manage NuGet Packages> Click the Browse and search for Microsoft.SqlServer.Types.
As picture shows, the vision is 14.0.
You can work around this issue by using assembly redirection in the application configuration file.
More details you can refer to Ian Kemp's answer.
Besides, you can also try another methods in this document.
Best Regards,
Daniel Zhang

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


Tuesday, January 21, 2020 8:12 AM ✅Answered

Hi DavidThi808,
If you need GEO functionality in .NET Core, you can use Redis GEO support or PostGIS.
More details you can refer to these links.
[Use SqlGeography at ServiceStack.OrmLite in .Net Core]
[Implement SqlGeography and SqlGeometry for Spatial Types support for .Net Core]
Hope these are helpful for you.
Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
Best Regards,
Daniel Zhang

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


Monday, January 20, 2020 12:14 PM

Hi Daniel;

Thank you for adding the .NET Framework restriction info - that's critical for us. Our code needs to run on .NET Core. Correct me if I'm wrong but SqlGeometry is .NET Framework only and therefore we can't use it in .NET Core, even with the SqlGeometry.Deserialize(reader.GetSqlBytes(0)); approach.

??? - thanks - dave

What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing


Tuesday, January 21, 2020 11:32 AM

thank you

What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing