Using Sql.executeTransactionAsync results in TypeLoadException
yreynhout opened this issue ยท 11 comments
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).
For reference, the full message we saw (from linked @thomasd3 #117 (comment)):
---> System.TypeLoadException: Could not load type 'System.Data.Common.DbBatch' from assembly 'Npgsql, Version=6.0.4.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7'.
at Ply [Npgsql.FSharp.Sql+body@365-13.Invoke](mailto:Npgsql.FSharp.Sql+body@365-13.Invoke)()
at Ply Ply.TplPrimitives.tryFinally(FSharpFunc<void, Ply> continuation, FSharpFunc<void, void> finallyBody)
at Ply [Npgsql.FSharp.Sql+executeTransactionAsync@346-5.Invoke](mailto:Npgsql.FSharp.Sql+executeTransactionAsync@346-5.Invoke)()
Thanks @yreynhout @abelbraaksma for the detailed report. I've just got back from vacation, so I will try to fix the problem ASAP. Since net6.0 is LTS now, would it be alright to have the new version support only net6.0
as the target framework?
Hi there. I can confirm the issue:
System.TypeLoadException: Could not load type 'System.Data.Common.DbBatch' from assembly 'Npgsql, Version=6.0.4.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7'.
at Npgsql.FSharp.Sql.body@365-13.Invoke(Unit unitVar)
at Ply.TplPrimitives.tryFinally[u](FSharpFunc`2 continuation, FSharpFunc`2 finallyBody)
Since net6.0 is LTS now, would it be alright to have the new version support only net6.0 as the target framework?
For me that would absolutely work ๐
Since net6.0 is LTS now, would it be alright to have the new version support only net6.0 as the target framework?
That would work for me as well, but I have no idea what the wider audience of consumers is targeting. Being forced to upgrade to .net 6.0
could be a deal-breaker for some. OTOH, you could go ahead and wait for that complaint to surface as an issue.
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 ๐
Thank you very much @Zaid-Ajaj. Will check it out soon ๐
Thanks @Zaid-Ajaj ! I'll be able to test in the next few days.
@Zaid-Ajaj, I just tested this over the weekend and it appears to work like a charm. Thanks for fixing this!
I updated to the latest package as well, and it works like a charm. Thanks!
Thanks for confirming everyone ๐
works on my end as well! thanks