"Can't write CLR type System.Byte[] with handler type NetTopologySuiteHandler"
See original GitHub issueHello 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:
- Created 5 years ago
- Comments:9 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 aDbContext
, 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.
Thanks, will investigate as soon as possible.