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.

"Can't write CLR type System.Byte[] with handler type NetTopologySuiteHandler"

See original GitHub issue

Hello everyone,

I am using Npgsql and NetopologySuite plugin to work with Postgres db. Today I face an issue that Can't write CLR type System.Byte[] with handler type NetTopologySuiteHandler when save NetopologySuite.Geometries.MultiPoint into the database in geometry type column. I don’t know what is this problem? Here are my configurations followed official docs from MS

   protected override void OnModelCreating(ModelBuilder builder)
     {
         builder.HasPostgresExtension("postgis");
     }


     services.AddDbContext<CSContext>(option =>
      {
             option.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"),
                 x => x.UseNetTopologySuite());
      });

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
YohDeadfallcommented, Mar 3, 2019

You’re using NHibernate.Spatial which automatically converts an geometry to a byte array, but Npgsql expects a geometry object. This is because you call the UseNetTopologySuite method when configuring a DbContext, and this method registers the NTS plugin globally:

https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/blob/10802aef53e3f61b9cc068986b52ccbfea630a84/src/EFCore.PG.NTS/Extensions/NpgsqlNetTopologySuiteDbContextOptionsBuilderExtensions.cs#L32-L33

So you need to use the RawPostgis plugin and do not register NTS in EF, or you need to teach NHibernate not to handle conversion automatically. Probably the last thing means that you shouldn’t use NHibernate.Spatial.

Closing the issue as there is no bug in Npgsql, but feel free to continue the discussion.

1reaction
YohDeadfallcommented, Feb 28, 2019

Thanks, will investigate as soon as possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# with Npgsql - Can't write CLR type System.String with ...
In my database I have a column that type Integer. If you want to add data this column, You should use NpgsqlDbType.Integer datatype....
Read more >
"Can't write CLR type System.Byte[] with handler ...
Today I face an issue that Can't write CLR type System.Byte[] with handler type NetTopologySuiteHandler when save NetopologySuite.Geometries.
Read more >
"Can't write CLR type System.Boolean with handler ...
I am getting an exception "Can't write CLR type System.Boolean with handler type Int64Handler" in the OrganizationUnitAppService.
Read more >
Class NpgsqlTypeHandler<TDefault>
Base class for all type handlers, which read and write CLR types into their PostgreSQL ... The default CLR type that this handler...
Read more >
C# with Npgsql - Can't write CLR type ... - appsloveworld.com
In my database I have a column that type Integer. If you want to add data this column, You should use NpgsqlDbType.Integer datatype....
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