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.

Using Sql.executeTransactionAsync results in TypeLoadException

See original GitHub issue

With the latest releases of Npgsql.FSharp (5.0.0, 5.0.1, 5.1.0) we started to observe the TypeLoadException when trying to use Sql.executeTransactionAsync. These are the first releases that use DbBatch (in the form of NpgsqlBatch) for speeding up transactions. And therein lies the problem …

If you look at Npgsql itself, you can see it targets different frameworks. Not only that but what is in the Npgsql assembly depends on which target framework it is built for. For netstandard2.0 you can see it embeds System.Data.Common.DbBatch and friends (probably because it’s not available in netstandard2.0) in the Npgsql assembly. For net6.0 you can see it references System.Data.Common and uses DbBatch and friends from that assembly. Npgsql.FSharp ships as a netstandard2.0 package. Now, when a consumer of this package is itself targeting net6.0, it will get Npgsql.FSharp as netstandard2.0 since that’s the only thing available, and Npgsql as net6.0 (with the reference to, not the embedded DbBatch). I’m no expert in these matters, but it seems that the Npgsql.FSharp metadata thinks it will find the System.Data.Common.DbBatch type in the Npgsql assembly, when in reality it is in the System.Data.Common assembly. This could explain why the TypeLoadException message is Could not load type 'System.Data.Common.DbBatch' from assembly 'Npgsql, Version=6.0.4.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7'..

To get it to work properly, I think Npgsql.FSharp needs to multi-target both frameworks, causing the metadata to line up. I think this goes for net5.0 too (I haven’t tested it).

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Zaid-Ajajcommented, Jun 23, 2022

@yreynhout @aspnetde

Npgsql.FSharp v5.2.0 has been published 🚀 now targeting net6.0 only. Removes Ply because now we are using native task.

OTOH, you could go ahead and wait for that complaint to surface as an issue.

Yeah, that’s the idea for the time being. Would love to hear from anyone who is facing the issue 🙏

0reactions
thomasd3commented, Jun 29, 2022

works on my end as well! thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

System.TypeLoadException at OnConfiguring method
I solved this by installing the latest version of Microsoft.EntityFrameworkCore.SqlServer . I was using version 1.1.0 and I had the latest ...
Read more >
Realm executeTransactionAsync dont write data to DB
I use realm db in my project. I want to write some data from JSON in my assets folder to realm when app...
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