Using Sql.executeTransactionAsync results in TypeLoadException
See original GitHub issueWith 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:
- Created a year ago
- Reactions:2
- Comments:11 (8 by maintainers)

Top Related StackOverflow Question
@yreynhout @aspnetde
Npgsql.FSharp v5.2.0 has been published 🚀 now targeting net6.0 only. Removes Ply because now we are using native
task.Yeah, that’s the idea for the time being. Would love to hear from anyone who is facing the issue 🙏
works on my end as well! thanks