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=10.0.0.0, 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.
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));
User contributions licensed under CC BY-SA 3.0