Npgsql.Bulk icon indicating copy to clipboard operation
Npgsql.Bulk copied to clipboard

Datamodel gives System.InvalidProgramException: Common Language Runtime detected an invalid program.

Open JoschaMetze opened this issue 4 years ago • 6 comments

Hi,

I tried bulk updater in a complex datamodel. Unfortunately it fails in the generated WriterForInsertAction with a InvalidProgramException. I tried to isolate the problem but have not been very successfull yet. It seems to be the problem when I want to insert an entity that might be linked in another entity.

Is there a way to debug this somehow? I tried to work around this a little bit, it seems to be related to the nullable-Path (underlying!=null). But my IL-Skills are not the best unfortunately. I was not able to create a repro case that I might be able to share.

Any ideas? The InvalidProgramException doesn't give more details.

Entity_a494b9d3_73cd_46c9_bb15_dc181ae254c8_1.WriterForInsertAction(Messlokation , NpgsqlBinaryImporter , OperationContext ) NpgsqlBulkUploader.WriteInsertPortion[T](IEnumerable1 list, EntityInfo mapping, NpgsqlConnection conn, String tempTableName, NpgsqlBulkCodeBuilder1 codeBuilder) Zeile 343 NpgsqlBulkUploader.Insert[T](IEnumerable1 entities, InsertConflictAction onConflict) Zeile 281 NpgsqlBulkUploader.Insert[T](IEnumerable1 entities) Zeile 218

Cheers, Joscha

JoschaMetze avatar Dec 08 '20 12:12 JoschaMetze

Hi @JoschaMetze , hm, this is strange. Yeah, this kind of errors are very hard to debug, but I'm very surprised this happened. May I know what versions of .Net, EF and Npgsql you are using? How many properties in your model class? Is it big? You suspect it is related to nullable properties? I could try to do some investigations on my side.

neisbut avatar Dec 16 '20 09:12 neisbut

Hi, we are using ef core 3.1.6 in a netcoreapp 3.1. I've tried Npgsql 0.9.0 and 0.8.4 (as well as compiling from source). My model is pretty big in total, I've attached a snippet from the context model snapshot to give you an idea. A single entity wasn't enough to trigger the error, but it was always linking between several entities that triggered it. I suppose it was because of the nullable as I commented the specific code path in the CodeBuilder class (or better put a jump in the emitted IL to skip it) and then I couldn't reproduce it anymore (but as later code paths depend on that information from the CodeBuilder it crashes later on ;) ) I can't share the model completely as it is closed source (and a customers IP), but I can supply more information if you need something. snapshot.txt

JoschaMetze avatar Dec 16 '20 09:12 JoschaMetze

Hi !

I've got the same problem, I went from 0.7.7.1 To 0.8.x and that error start. I have a simple model with 2 int, 3 Guid, 2 DateTime and 1 string...

Thanks !

BaptisteLemarcis avatar Dec 24 '20 16:12 BaptisteLemarcis

Hi!

I've got the same problem when used "InsertAsync". It crashes on one PC of 4. dotnet version is 3.1.8, bulk version is 0.8.2

InvalidProgramException: Common Language Runtime detected an invalid program.\r\nSTACK TRACE: at ConsumerEntity_c8b586f0_1415_4179_9b7b_9eaf5f88749c_59.WriterForInsertAction(ConsumerEntity , NpgsqlBinaryImporter , DbContext )\r\n at Npgsql.Bulk.NpgsqlBulkUploader.WriteInsertPortion[T](IEnumerable1 list, EntityInfo mapping, NpgsqlConnection conn, String tempTableName, NpgsqlBulkCodeBuilder1 codeBuilder)\r\n at Npgsql.Bulk.NpgsqlBulkUploader.InsertAsync[T](IEnumerable`1 entities, InsertConflictAction onConflict)

KovtunV avatar Jan 22 '21 11:01 KovtunV

Hi,

we have got the same problem using efcore 5.0.4 and npgsql 0.9.0. It's on a complex object and fail at the first InsertAsync.

Common Language Runtime detected an invalid program. Stack: at TestModel_0d86a22c_0cfa_44f2_a4c8_9b431e857dd2_3.WriterForInsertAction(TestModel , NpgsqlBinaryImporter , OperationContext ) at Npgsql.Bulk.NpgsqlBulkUploader.WriteInsertPortion[T](IEnumerable1 list, EntityInfo mapping, NpgsqlConnection conn, String tempTableName, NpgsqlBulkCodeBuilder1 codeBuilder) at Npgsql.Bulk.NpgsqlBulkUploader.InsertAsync[T](IEnumerable`1 entities, InsertConflictAction onConflict) (...)

We tried using npgsql 0.10.1 and we got the same error.

The complex object use these types.

  • Guid and Guid?
  • DateTime and DateTime?
  • Many instance of other object;
  • One instance of same object (previous ref);
  • ICollection<>
  • string
  • int
  • double?
  • float?
  • ushort
  • one Owned, but it's not the case here (bulk works with another one using Owned)

Hope this is helpful,

Cheers,

KhamaiFr avatar Jan 18 '22 12:01 KhamaiFr

@neisbut Hi, any progress?

KovtunV avatar Oct 18 '22 06:10 KovtunV