Cannot initialize SpatialServiceType

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
Feneck91
Posts: 50
Joined: Mon 12 Aug 2013 13:52

Cannot initialize SpatialServiceType

Post by Feneck91 » Wed 15 Jul 2015 10:11

Hello,

I have a problem with Spatial service initialization...

When I try to initialize spatial service type like :

Code: Select all

            var config = Devart.Data.PostgreSql.Entity.Configuration.PgSqlEntityProviderConfig.Instance;
            config.SpatialOptions.SpatialServiceType = SpatialServiceType.NetTopologySuite;
I have an exception : Cannot cast object type 'Devart.Data.PostgreSql.Entity.Spatials.PgSqlNetTopologySuiteSpatialServices" in type "Devart.Common.Entity.EntitySpatialServices" ?

If I initialize like

Code: Select all

            var config = Devart.Data.PostgreSql.Entity.Configuration.PgSqlEntityProviderConfig.Instance;
            config.SpatialOptions.SpatialServiceType = WellKnownBinary;
It't work but I have later an exception : "This functionality is not supported by Well-Known Binary (WKB) spatial service."

I worked with Oracle version, uninstall it (old version not compatible with Devart PostgreSQL 7.3) and install new version of Devart PostgreSQL.
Update NetTopologySuite to 1.13.3

Didn't understand the problem !
Thanks for reply.

I have removed and add Devart.Data / Devart.Data.Linq / Devart.Data.PostgresSQL / Devart.Data.PostgresSQL.Entity / Devart.Data.PostgresSQL.Entity.Spatials
I can call config.SpatialOptions.SpatialServiceType = SpatialServiceType.NetTopologySuite;

But now, when I migrate database, I have an error : the geometry type doesn't exists.
I do :

Code: Select all

            // Initialise GeoAPI
            GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices();

            var config = Devart.Data.PostgreSql.Entity.Configuration.PgSqlEntityProviderConfig.Instance;
            
            config.Workarounds.IgnoreSchemaName = true;

            // Tronque les clefs étrangère à 30 caractères sinon impossible de créer le schéma de la base de données, les clefs
            // étrangères générées sont tout simplement trop longues !
            config.CodeFirstOptions.TruncateLongDefaultNames = true;

            // Configur options to use
            // NetTopologySuite need: GeoAPI
            //                                       NetTopologySuite
            //                                       PowerCollections
            //                                       SharpMap
            // http://blog.devart.com/enhanced-entity-framework-spatials-support-for-oracle-mysql-and-postgresql.html

            config.SpatialOptions.AlwaysUseGeometryDefaultSrid = true;
            config.SpatialOptions.AlwaysUseGeographyDefaultSrid = true;

            config.SpatialOptions.SpatialServiceType = Devart.Data.PostgreSql.Entity.Configuration.SpatialServiceType.NetTopologySuite;

Feneck91
Posts: 50
Joined: Mon 12 Aug 2013 13:52

Re: Cannot initialize SpatialServiceType

Post by Feneck91 » Fri 17 Jul 2015 06:42

I have re-install PosgreSQL and PosGis, recreate Spatial databse.
All working well now.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Cannot initialize SpatialServiceType

Post by Shalex » Fri 17 Jul 2015 11:48

Thank you for your feedback.

Feneck91
Posts: 50
Joined: Mon 12 Aug 2013 13:52

Re: Cannot initialize SpatialServiceType

Post by Feneck91 » Thu 26 Nov 2015 08:31

Same problem after updating project to Visual 2015 + Update Devart dotConnect for PostgreSQL.

Code: Select all

        protected override void InitDatabaseModel()
        {
            GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices();

            var config = Devart.Data.PostgreSql.Entity.Configuration.PgSqlEntityProviderConfig.Instance;
            
            config.Workarounds.IgnoreSchemaName = true;

            // Tronque les clefs étrangère à 30 caractères sinon impossible de créer le schéma de la base de données, les clefs
            // étrangères générées sont tout simplement trop longues !
            config.CodeFirstOptions.TruncateLongDefaultNames = true;

            // Configurer les options spatiales à utiliser
            // NetTopologySuite demande à utiliser : GeoAPI
            //                                       NetTopologySuite
            //                                       PowerCollections

            config.SpatialOptions.AlwaysUseGeometryDefaultSrid = true;
            config.SpatialOptions.AlwaysUseGeographyDefaultSrid = true;

---> HERE EXCEPTION -->            config.SpatialOptions.SpatialServiceType =  Devart.Data.PostgreSql.Entity.Configuration.SpatialServiceType.NetTopologySuite;

            base.InitDatabaseModel();
        }
Exception : {"Impossible d'effectuer un cast d'un objet de type 'Devart.Data.PostgreSql.Entity.Spatials.PgSqlNetTopologySuiteSpatialServices' en type 'Devart.Common.Entity.EntitySpatialServices'."}
In english : {"cannot cast object of type 'Devart.Data.PostgreSql.Entity.Spatials.PgSqlNetTopologySuiteSpatialServices' to type 'Devart.Common.Entity.EntitySpatialServices'."}
What does it mean ?
Trying to uninstall / reinstall PostgreSQL + Postgis ...
Really angry ! When the production database will be used, I'll not able to destroy database each time I update software !

And I'm not sure this workaroud will work again ! The last time this has worked, I don't know really why !!
This don't work...
I have removed GeoAPI 1.7.4 / NetTopologySuite.1.14.0
replaced by
GeoAPI 1.7.2 / NetTopologySuite.1.13.3.2
Trying...

EDIT : Calling

Code: Select all

var tmpInstance = Devart.Data.PostgreSql.Entity.Spatials.PgSqlNetTopologySuiteSpatialServices.Instance;
Seem to resolve the problem. How this instance is created usually ?

Problem not solved, exception because NetTopologySuite cannot be loaded !
Problem with visual studio 2105 ? Compiled into 32 bits mode ?

EDIT : we have rebuild NetTopologySuite 1.14.0, I don't need anymore to call :

Code: Select all

var tmpInstance = Devart.Data.PostgreSql.Entity.Spatials.PgSqlNetTopologySuiteSpatialServices.Instance;
But, it seems that devart try to load 1.13.1 NetTopologySuite version, exceptions are raised :
[quote]Impossible de charger le fichier ou l'assembly 'NetTopologySuite, Version=1.13.1.0, Culture=neutral, PublicKeyToken=null' ou une de ses dépendances. La définition trouvée du manifeste de l'assembly ne correspond pas à la référence de l'assembly. (Exception de HRESULT : 0x80131040)/quote]

Not work since monday, please help me !

Feneck91
Posts: 50
Joined: Mon 12 Aug 2013 13:52

Re: Cannot initialize SpatialServiceType

Post by Feneck91 » Fri 27 Nov 2015 14:15

I understand...
  • Use NetTopologySuite 1.13.2 (only ?)
  • Use GeoAPI (I use 1.7.4 version)
  • Be carefull, PostgresSQL tools migration make reference to EF5, no EF6 (use Devart.Data.PosgreSql.Entity version 7.4.543.6 and not version 7.4.543.0)
  • Be carefull, PostgresSQL tools migration make reference to EF5, no EF6 (use Devart.Data.PosgreSql.Entity.Spatials version 7.4.543.6 and not version 7.4.543.0)
  • When I use the code : Devart.Data.PostgreSql.Entity.Spatials.PgSqlNetTopologySuiteSpatialServices.Instance;
    It's work because Visual also copy Devart.Data.PosgreSql.Entity.Spatials to output directory, without this line it does not do it ! So, make Copy Local to True to be sure the dll will be copied to executable folder.
It should be work now...

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Cannot initialize SpatialServiceType

Post by Shalex » Fri 27 Nov 2015 15:45

Thank you for sharing your experience.

Feneck91
Posts: 50
Joined: Mon 12 Aug 2013 13:52

Re: Cannot initialize SpatialServiceType

Post by Feneck91 » Mon 23 May 2016 12:50

Is latest version now support NetTopologySuite 1.14.0 ?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Cannot initialize SpatialServiceType

Post by Shalex » Thu 26 May 2016 09:31

Feneck91 wrote:Is latest version now support NetTopologySuite 1.14.0 ?
No, it doesn't.

This feature is on our roadmap, right after the .NET Core support. An approximate timeframe for its implementation is one or two months.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Cannot initialize SpatialServiceType

Post by Shalex » Fri 09 Dec 2016 16:05

dotConnect for PostgreSQL v7.7 includes the following features:
  • Signed versions of NetTopologySuite GIS library are supported in EF5/EF6
  • NetTopologySuite 1.14 is supported in EF5/EF6
  • GeoAPI 1.7.4 is supported in EF5/EF6
For more information, refer to viewtopic.php?f=3&t=34690.

Feneck91
Posts: 50
Joined: Mon 12 Aug 2013 13:52

Re: Cannot initialize SpatialServiceType

Post by Feneck91 » Tue 03 Jan 2017 13:16

I'm making migration, It's seem to compile...
But SpatialServiceType.NetTopologySuite is now obsolete.
Need to use SpatialServiceType.NetTopologySuiteUnsigned or SpatialServiceType.NetTopologySuiteSigned ?

SpatialServiceType.NetTopologySuiteUnsigned throws exceptions, SpatialServiceType.NetTopologySuiteSigned seems to work fine.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Cannot initialize SpatialServiceType

Post by Shalex » Wed 04 Jan 2017 09:07

That is correct.

JIC:
  • The NetTopologySuiteSigned and NetTopologySuiteUnsigned members are added to the SpatialServiceType enum in EF5/EF6
  • The behaviour is changed: the functionality of SpatialServiceType.NetTopologySuiteSigned is moved to Devart.Data.PostgreSql.Entity.EF5.dll / Devart.Data.PostgreSql.Entity.EF6.dll

Feneck91
Posts: 50
Joined: Mon 12 Aug 2013 13:52

Re: Cannot initialize SpatialServiceType

Post by Feneck91 » Mon 09 Jul 2018 16:32

I have exactly this problem witn PostgreSQL : viewtopic.php?t=34424

I'm using

Code: Select all

config.SpatialOptions.SpatialServiceType = Devart.Data.PostgreSql.Entity.Configuration.SpatialServiceType.NetTopologySuiteSigned;
When I make this request :

Code: Select all

Devart.Common.DbParameterBase []dbArrayParameters = new Devart.Common.DbParameterBase[1];
DbGeometry myDBGeometry = .... code to get a DbGeometry;
dbArrayParameters[0] = new PgSqlParameter("@mygeometry", myDBGeometry);
dbVectorSource.Database.ExecuteSqlCommand("the sql command", dbArrayParameters);
I have an exception "cannot convert value":
à Devart.Data.PostgreSql.PgSqlUtils.ObjectToByteArray(Object value, Type type, Encoding encoding)
à Devart.Data.PostgreSql.PgSqlUtils.ParamValueToBytes(String version, Encoding encoding, PgSqlType pgSqlType, Object val, Int32 typeOid, Boolean integerDateTime)
à Devart.Data.PostgreSql.PgSqlCommand.a(String A_0, Encoding A_1, ArrayList A_2, Boolean A_3)
à Devart.Data.PostgreSql.PgSqlCommand.InternalExecute(CommandBehavior behavior, IDisposable stmt, Int32 startRecord, Int32 maxRecords)
à Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior, Boolean nonQuery)
à Devart.Common.DbCommandBase.ExecuteNonQuery()
à System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
à System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
à System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreCommandInternal(String commandText, Object[] parameters)
à System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
à System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass59.<ExecuteStoreCommand>b__57()
If I use "Devart.Data.PostgreSql.Entity.Configuration.SpatialServiceType.NetTopologySuiteUnsigned" instead, I have this exception :
System.IO.FileLoadException
HResult=0x80131040
Message=Impossible de charger le fichier ou l'assembly 'NetTopologySuite, Version=1.13.2.0, Culture=neutral, PublicKeyToken=null' ou une de ses dépendances. La définition trouvée du manifeste de l'assembly ne correspond pas à la référence de l'assembly. (Exception de HRESULT : 0x80131040)
Source=Devart.Data.PostgreSql.Entity.Spatials.EF6
Arborescence des appels de procédure :
at Devart.Common.Entity.ba.a(Int32 A_0, Boolean A_1)
at Devart.Common.Entity.ba.b(Int32 A_0)
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.GetSpatialPropertyValueWithErrorHandling[TProperty](Int32 ordinal, String propertyName, String typeName, PrimitiveTypeKind spatialTypeKind)
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)
at System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.RowNestedResultEnumerator.MaterializeRow()
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.RowNestedResultEnumerator.MoveNext()
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.ObjectQueryNestedEnumerator.TryReadToNextElement()
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.ObjectQueryNestedEnumerator.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at DataManagerDAL.UtilisateurProvider.FindUserByID(Int64 _id, Boolean _bWithProfiles, Boolean _bWithChantiers) in D:\Dev\GeoMaps\GeomapsDataManagerRepo\DataManager\03-source\DataManager\DataManagerDAL\UtilisateurProvider.cs:line 203
at DataManager.ViewModel.PageChantiersViewModel.OnLoginChanged(LoginMessage _oLoginMessage) in D:\Dev\GeoMaps\GeomapsDataManagerRepo\DataManager\03-source\DataManager\DataManager\ViewModel\PageChantiersViewModel.cs:line 853
at DataManager.ViewModel.BaseViewModelWithLogin.OnLoginChanged(NotificationMessage`1 _msgLogin) in D:\Dev\GeoMaps\GeomapsDataManagerRepo\DataManager\03-source\DataManager\DataManager\ViewModel\BaseViewModel.cs:line 41
Why does it need "NetTopologySuite, Version=1.13.2.0", I use ONLY the version : 1.14.0.0 ? (+ GeoAPI 1.7.4).

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Cannot initialize SpatialServiceType

Post by Shalex » Wed 11 Jul 2018 17:11

SpatialServiceType.NetTopologySuiteUnsigned should be used with unsigned NetTopologySuite up to v1.13.2.

SpatialServiceType.NetTopologySuiteSigned is designed for NetTopologySuite 1.14 or higher.
Feneck91 wrote: Mon 09 Jul 2018 16:32I have an exception "cannot convert value": [...]
Please upload a small test project with the corresponding DDL/DML script to ftp://ftp.devart.com (credentials: anonymous / yourEmail) so that we can reproduce the error in our environment.

Post Reply