question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Are Spatial Types like Geometry and Geography supported?

See original GitHub issue

I tried to fully switch from System.Data.SqlClient to Microsoft.Data.SqlClient and I am getting a NULL response when calling the DbDataReader.GetFieldType(ordinal) method.

Where, the ordinal corresponds to the index of any of the columns with Data Types (Geography or Spatial) from the database.

To the extent, my tests are failing with the following information below.

The weird thing is, why the System.Data.SqlClient is in the picture of the exception?

I only referenced the Microsoft.Data.SqlClient and have no references at System.Data.SqlClient.

Please advise and thanks.

Stack Trace:

 TestBaseRepositorySpatialsCrud
   Source: BaseRepositorySpatialsTest.cs line 39
   Duration: 959 ms

  Message: 
    Test method RepoDb.IntegrationTests.Types.Spatials.BaseRepositorySpatialsTest.TestBaseRepositorySpatialsCrud threw exception: 
    System.IO.FileNotFoundException: Could not load file or assembly '_System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a_'. The system cannot find the file specified.
  Stack Trace: 
    RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive)
    RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
    TypeNameParser.ResolveType(Assembly assembly, String[] names, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
    TypeNameParser.ConstructType(Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
    TypeNameParser.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
    Type.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError)
    SqlConnection.CheckGetExtendedUDTInfo(SqlMetaDataPriv metaData, Boolean fThrow) line 1870
    SqlDataReader.GetValueFromSqlBufferInternal(SqlBuffer data, _SqlMetaData metaData) line 2778
    SqlDataReader.GetValue(Int32 i) line 2668
    lambda_method(Closure , DbDataReader )
    DataReader.ToEnumerable[TEntity](DbDataReader reader, IDbConnection connection, IDbTransaction transaction)+MoveNext() line 36
    List`1.AddEnumerable(IEnumerable`1 enumerable)
    Enumerable.ToList[TSource](IEnumerable`1 source)
    EnumerableExtension.AsList[T](IEnumerable`1 value) line 71
    DbConnectionExtension.ExecuteQueryInternal[TEntity](IDbConnection connection, String commandText, Object param, Nullable`1 commandType, Nullable`1 commandTimeout, IDbTransaction transaction, Boolean skipCommandArrayParametersCheck) line 324
    DbConnectionExtension.QueryInternalBase[TEntity](IDbConnection connection, IEnumerable`1 fields, QueryGroup where, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, Int32 cacheItemExpiration, Nullable`1 commandTimeout, IDbTransaction transaction, ICache cache, ITrace trace, IStatementBuilder statementBuilder) line 1220
    DbConnectionExtension.QueryInternal[TEntity](IDbConnection connection, QueryGroup where, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, Int32 cacheItemExpiration, Nullable`1 commandTimeout, IDbTransaction transaction, ICache cache, ITrace trace, IStatementBuilder statementBuilder) line 294
    DbConnectionExtension.Query[TEntity](IDbConnection connection, QueryGroup where, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, Int32 cacheItemExpiration, Nullable`1 commandTimeout, IDbTransaction transaction, ICache cache, ITrace trace, IStatementBuilder statementBuilder) line 246
    DbConnectionExtension.Query[TEntity](IDbConnection connection, Expression`1 where, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, Int32 cacheItemExpiration, Nullable`1 commandTimeout, IDbTransaction transaction, ICache cache, ITrace trace, IStatementBuilder statementBuilder) line 198
    DbRepository`1.Query[TEntity](Expression`1 where, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, IDbTransaction transaction) line 97
    BaseRepository`2.Query(Expression`1 where, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, IDbTransaction transaction) line 64
    BaseRepositorySpatialsTest.TestBaseRepositorySpatialsCrud() line 55

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:23 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
MaceWinducommented, Feb 21, 2020

You cannot use those types with Microsoft.Data.SqlClient, because they build against System.Data.SqlClient and use types declared there. Only solution is to manually build dotMorten.Microsoft.SqlServer.Types against Microsoft.Data.SqlClient (well, actually with some ugly hacks it is possible for .net framework, but for .net core it is the only way)

Ideally Microsoft could fix it by providing more flexible mechanisms to load UDT types

1reaction
ajcvickerscommented, Feb 17, 2020

@mikependon In case it helps, EF Core supports SQL Server spatial columns on .NET Core by mapping them to types from the community NTS project

These aren’t the same native SQL Server types exposed on .NET Framework, but a lot of the same functionality is supported. Docs: https://docs.microsoft.com/en-us/ef/core/modeling/spatial

Read more comments on GitHub >

github_iconTop Results From Across the Web

BUG-000122070: Shapes that are stored using third-party ...
ArcGIS is unable to display certain shapes from a feature class stored using third-party spatial types inside an enterprise database.
Read more >
Spatial Data Types Overview - SQL Server
There are two types of spatial data. The geometry data type supports planar, or Euclidean (flat-earth), data. The geometry data type both ...
Read more >
Using geometry rather than geography data types in SQL ...
The geography type is a little bit more restrictive than geometry. ... use all the capabilities of the spatial database, spatial functions, ...
Read more >
Introduction to SQL Server Spatial Data - Simple Talk
SQL Server supports two spatial data types: Geometry : Stores data based on a flat (Euclidean) coordinate system. The data type is often ......
Read more >
Working with geospatial data | BigQuery
In BigQuery, the GEOGRAPHY data type represents a geometry value or geometry collection. To represent spatial features, create a table with a GEOGRAPHY...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found