1

During creating Polygon it throws execution. I am using library Microsoft.SqlServer.Types latest version 160.

polyText = "POLYGON ((
45.3972179 8.8406638000000157, 
45.4215054 8.9151509000000715,
45.4001544 8.9361126999999669, 
45.4016369 8.9607184999999845, 
45.3851877 8.9621395000000348,
45.3853039 8.948319999999967, 
45.3747296 8.9535720999999739, 
45.3858019 8.9360727000000679, 
45.3579525 8.8890794000000142, 
45.3414371 8.90664240000001, 
45.3452409 8.91328980000003, 
45.3273192 8.92622259999996, 
45.3185438 8.9208002999999962, 
45.3405949 8.8954118000000335, 
45.3471543 8.866777299999967, 
45.3587372 8.8690788999999768, 
45.3675493 8.8504374999999982, 
45.3972179 8.8406638000000157, 
45.3972179 8.8406638000000157, 
45.3972179 8.8406638000000157
))
"

SqlGeography poly = SqlGeography.STGeomFromText(new SqlChars(polyText), 4326);

Exception statk

SQL Server Spatial library could not be loaded. Error code: 126 (HResult: 0x80131524).
Microsoft.SqlServer.Types

System.IO.FileNotFoundException: SQL Server Spatial library could not be loaded. Error code: 126 (HResult: 0x80131524).
   at Microsoft.SqlServer.Types.GLNativeMethods.ThowIfGLNativeLibraryNotLoaded()
   at Microsoft.SqlServer.Types.GLNativeMethods.GeodeticIsValid(GeoData& g, Double eccentricity, Boolean forceKatmai)
   at Microsoft.SqlServer.Types.SqlGeography.IsValidExpensive(Boolean forceKatmai)
   at Microsoft.SqlServer.Types.SqlGeography..ctor(GeoData g, Int32 srid)
   at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)
   at Microsoft.SqlServer.Types.SqlGeography.STGeomFromText(SqlChars geometryTaggedText, Int32 srid)
   at webNet.Area.Default.DrawShapesFromSql(String polyText, String areaName) in C:\Project\webNet\Area\Default.aspx.cs:line 474
   at webNet.Area.Default.LoadForm() in C:\Project\webNet\Area\Default.aspx.cs:line 93

Created SqlGeography.Point it works fine without problem, only creating reading inserting polygon due it throws error.

Thom A
  • 88,727
  • 11
  • 45
  • 75
  • Don't know about the library error but it's not a valid polygon: the starting point and ending point should be the same to form a closed loop, but the last point is repeated an extra two times. – AlwaysLearning Dec 13 '22 at 11:46
  • I tried with different one also error was occurred. For instance when I run this command on sql side it return a data to me. but when I run it on c# side it returns error. – Kamran Musayev Dec 13 '22 at 11:48
  • I'm getting the same issue with net48, EntityFramework v6.3.0, [Microsoft.SqlServer.Types v160.1000.6](https://www.nuget.org/packages/Microsoft.SqlServer.Types/) with the binding redirect ``. [Provider Support for Spatial Types](https://learn.microsoft.com/en-us/ef/ef6/fundamentals/providers/spatial-support) indicates the EF6 provider depends on some additional low-level libraries however I assumed installing the `Microsoft.SqlServer.Types` package would be sufficient. – Peter Riesz Jan 09 '23 at 16:31

1 Answers1

0

I managed to resolve this exception by downgrading Microsoft.SqlServer.Types to version 14

Peter Riesz
  • 3,091
  • 29
  • 33