Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JoschaMetze opened this issue Dec 8, 2020 · 6 comments

Comments

@JoschaMetze
Copy link

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

@neisbut
Copy link
Owner

neisbut commented Dec 16, 2020

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.

@JoschaMetze
Copy link
Author

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

@BaptisteLemarcis
Copy link

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 !

@KovtunV
Copy link

KovtunV commented Jan 22, 2021

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)

@KhamaiFr
Copy link

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,

@KovtunV
Copy link

KovtunV commented Oct 18, 2022

@neisbut Hi, any progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants