SqlDataReader.GetValue not successful for geometry columns


When I have a SqlDataReader on a table where the geometry type is used, reader.GetFieldType(index) returns null and reader.GetValue(index) results in

System.IO.FileLoadException: 'Could not load file or assembly 'Microsoft.SqlServer.Types, Version=, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

I tried to add the nuget package Microsoft.SqlServer.Types v14.0.1016.290, but that does not remedy the problem.

asked on Stack Overflow May 26, 2021 by Anders Lindén • edited May 26, 2021 by marc_s

1 Answer


I haven't used the geometry type yet, just read documentation. The geometry represents a point in a coordinate system, it is stored as binary. So try this:

SqlGeometry geometry = new SqlGeometry();
geometry.Read(new BinaryReader(reader.GetSqlBytes(index).Stream));
answered on Stack Overflow May 26, 2021 by Tim Schmelter

User contributions licensed under CC BY-SA 3.0