Writing values of 'Pgvector.Vector' is not supported for parameters having no NpgsqlDbType or DataTypeName. Try setting one of these values to the expected database type
Sorry I never do this but after 2 days I can't crack this nut and have reached my limit 😂
I've been getting this error when trying to save a type with a Vector column in it...
Writing values of 'Pgvector.Vector' is not supported for parameters having no NpgsqlDbType or DataTypeName. Try setting one of these values to the expected database type..
at Npgsql.Internal.AdoSerializerHelpers.<GetTypeInfoForWriting>g__ThrowWritingNotSupported|1_0(Type type, PgSerializerOptions options, Nullable`1 pgTypeId, Nullable`1 npgsqlDbType, Exception inner)
at Npgsql.Internal.AdoSerializerHelpers.GetTypeInfoForWriting(Type type, Nullable`1 pgTypeId, PgSerializerOptions options, Nullable`1 npgsqlDbType)
at Npgsql.NpgsqlParameter.ResolveTypeInfo(PgSerializerOptions options)
at Npgsql.NpgsqlParameterCollection.ProcessParameters(PgSerializerOptions options, Boolean validateValues, CommandType commandType)
at Npgsql.NpgsqlCommand.<ExecuteReader>d__120.MoveNext()
at Npgsql.NpgsqlCommand.<ExecuteReader>d__120.MoveNext()
at Npgsql.NpgsqlCommand.<ExecuteDbDataReaderAsync>d__113.MoveNext()
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.<ExecuteReaderAsync>d__18.MoveNext()
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.<ExecuteReaderAsync>d__18.MoveNext()
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.<ExecuteAsync>d__50.MoveNext()
I've tried everything I can, today I created minimal projects following your guides, then another using IdentityDbContext thinking that may be the issue, nothing seems to fix it. I downloaded the Npgsql source code and mounted it to see where this exception was thrown and debug from there but couldn't figure it out much further.
My repo is relatively small it's just some prototyping with Razor Pages and your stuff. If you clone the commit linked below, startup the pg17 docker container, and try to run the DndTest project, it will try to do an insert of the type and reproduce the error immediately. The other projects are attempts at minimal reproductions but they don't reproduce 😭
Or if you just take a look at the source code or have some recommendations of things to try before doing that it would all be greatly appreciated 🙏
https://github.com/Issung/SemanticDnd/commit/83d430bfc82567575f6262a1f06abbedc23d1811
Hi @Issung, this looks like the same error as #31 and #41 (likely missing a call to useVector somewhere).
Thanks for the reply @ankane. I have this in my Program.cs. It works well enough that it is able to create the initial migration. I'll try doing it in the DbContext's OnConfiguring override and see if that fixes it.
builder.Services.AddDbContext<DndDbContext>(options =>
{
options.UseNpgsql(connectionString, o => o.UseVector());
options.EnableSensitiveDataLogging();
});
That didn't fix it..
I cloned my project and started trimming things out until the program started to work.. What makes it or breaks it is app.UseHangfireDashboard()... I guess because it also uses the postgres database? Very bizarre. I can try to make a minimal reproducible example, but not sure who the fix would need to come from, you guys or the Hangfire.PostgreSql guys.. 😅
Looks like others have run into this as well: https://github.com/hangfire-postgres/Hangfire.PostgreSql/issues/316
It sounds like Hangfire.PostgreSql has the same issue with NodaTime and there's a workaround: https://github.com/hangfire-postgres/Hangfire.PostgreSql/issues/322#issuecomment-1710694316
We may be able to remove the NpgsqlConnection.GlobalTypeMapper call like other extensions did in https://github.com/npgsql/efcore.pg/pull/3167, which may fix it.
Switched to the new plugin approach in this branch, but it requires EF Core 9.
You're a couple steps ahead of me! Here's the minimal reproducible example. If it's not of use to you any more maybe it will be for someone else in the future, so I'll upload it anyway :)
Switched to the new plugin approach in this branch, but it requires EF Core 9.
@ankane looks great, this is definitely the right direction from 9.0 onwards.
@roji Thanks for taking a look.
@Issung I probably won't merge / drop support for EF Core 8 until EF Core 10 is released, so I'd recommend using the workaround linked above in the meantime.
Hi @ankane , I have the same error. I use EF core 8 and not missing UseVector(). Can you give me how to fix that error.
---> Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.
---> System.InvalidCastException: Writing values of 'Pgvector.Vector' is not supported for parameters having no NpgsqlDbType or DataTypeName. Try setting one of these values to the expected database type..
at Npgsql.Internal.AdoSerializerHelpers.<GetTypeInfoForWriting>g__ThrowWritingNotSupported|1_0(Type type, PgSerializerOptions options, Nullable1 pgTypeId, Nullable1 npgsqlDbType, Exception inner)
at Npgsql.Internal.AdoSerializerHelpers.GetTypeInfoForWriting(Type type, Nullable1 pgTypeId, PgSerializerOptions options, Nullable1 npgsqlDbType)
at Npgsql.NpgsqlParameter.ResolveTypeInfo(PgSerializerOptions options)
at Npgsql.NpgsqlParameterCollection.ProcessParameters(PgSerializerOptions options, Boolean validateValues, CommandType commandType)
at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
Same problem here
[04:41:43 ERR] An exception occurred while iterating over the results of a query for context type 'Equibles.Core.Data.Contexts.ApplicationDbContext'.
System.InvalidCastException: Writing values of 'Pgvector.Vector' is not supported for parameters having no NpgsqlDbType or DataTypeName. Try setting one of these values to the expected database type..
at Npgsql.Internal.AdoSerializerHelpers.<GetTypeInfoForWriting>g__ThrowWritingNotSupported|1_0(Type type, PgSerializerOptions options, Nullable`1 pgTypeId, Nullable`1 npgsqlDbType, Exception inner)
at Npgsql.Internal.AdoSerializerHelpers.GetTypeInfoForWriting(Type type, Nullable`1 pgTypeId, PgSerializerOptions options, Nullable`1 npgsqlDbType)
at Npgsql.NpgsqlParameter.ResolveTypeInfo(PgSerializerOptions options)
at Npgsql.NpgsqlParameterCollection.ProcessParameters(PgSerializerOptions options, Boolean validateValues, CommandType commandType)
at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
I am calling UseVector()
@ankane, any expectation on when to merge and release the config-plugin branch? As the library is not usable in its current version. EF Core 8 users can opt not to upgrade to the most recent version.
Hi! Workaround, just added to my config in Program.cs:
#pragma warning disable CS0618
//Vector type workaround
NpgsqlConnection.GlobalTypeMapper.UseVector();
#pragma warning restore CS0618
During play with this issue I also updated to Net 9.0 with Core 9.0 and so on, don't want to revert so cannot say if it helps for 8.0
Try to integrate pgvector with NHibernate, got the same error, I'm sure I have called UseVector() method, because I can query Vector but can not save it.
Full code is https://github.com/beginor/nhibernate-extensions/tree/master/src/NHibernate.Extensions.Pgvector.
temp save workaround is:
but can used with any distance operators like <=>
Merged the new plugin approach in the commit above.