npgsql: Using Npgsql 5.0.7 via nuget on .NET 4.8 gives MissingMethodException in ChannelReader
Exception:
Method not found: 'System.Threading.Tasks.ValueTask`1<Boolean> System.Threading.Channels.ChannelReader`1.WaitToReadAsync(System.Threading.CancellationToken)'.
Stacktrace:
at Npgsql.ConnectorPool.<>c__DisplayClass38_0.<<Rent>g__RentAsync|0>d.MoveNext()
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
at Npgsql.ConnectorPool.<>c__DisplayClass38_0.<Rent>g__RentAsync|0()
at Npgsql.ConnectorPool.Rent(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnection.<>c__DisplayClass41_0.<<Open>g__OpenAsync|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlConnection.Open()
at SD.LLBLGen.Pro.Gui.Controls.WizardPages.MetaDataRetrievalWizard_Step_ConnectionData.TestConnectionData(Boolean showSuccess) in C:\MyProjects\VS.NET Projects\LLBLGen Pro v5.9\Designer\Gui\Controls\WizardPages\MetaDataRetrievalWizard_Step_ConnectionData.cs:line 245
It’s in my driver, where I obtain the factory using NpgsqlFactory.Instance as I now directly reference the Nuget package. I compile against 4.8 (against 4.7.2 same issue). I copy all necessary files to the output folder, app using the driver is running on .net 4.8, I checked. All I do is obtaining a connection from the factory and then call Open.
I am using this route because Npgsql doesn’t ship an msi anymore so I have to reference the Npgsql package directly to make my users not have to fight where to get the files.
I have no idea what to do nor what I’m doing wrong. It looks like I have to reference another package somewhere but which one is a blur to me.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 25 (22 by maintainers)
OK, took a look.
After building everything successfully, running NpgsqlRepro.exe failed with:
Looking at the actual System.Runtime.CompilerServices.Unsafe.dll deployed in Drivers\PostgreSQL, it had a version of 6.0.0, so I amended the binding redirects. When that didn’t work, I noticed that the
<dependentAssembly>directives are outside of the<assemblyBinding>node - so I moved them in. At this point the program connected, but threw another runtime binding redirect exception for System.Text.Json, after I added that everything worked…There already was a 6-month gap there, I’d like to make sure this gets closed this time 😉
Great, happy to lay this to rest 😃 Binding redirects are a small piece of hell, but at least it’s possible to make stuff work, with enough pain.
@roji alright! 👍 😃 Glad it’s sorted. Sorry I had the binding redirects at the wrong spot… 😦 So the end result is: it can work, with enough binding redirects.
v6 works, at least you don’t get the missing method exception but then you get the system.buffers crap.
Will now as a final test see if the redirects fix it, just for completeness
Npgsql version: Npgsql, Version=5.0.7.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7 So that’s not v6. Will check with that.
I also got this error message with Npgsql 5.0.7 on .NET 4.8. In my case I had an old version installed in GAC (Npgsql 4.0, using the msi) which disturbed 5.0.x. Uninstalling the old version helped in my case.
@roji
Well, I managed to repro it with a console app and 2 assemblies 😃 I’ve attached the repro below.
NpgsqlRepro now loads as we do in our main app, but here I use hardcoded strings, the PostgreSQL driver dll, gets the factory, creates a connection using the factory and then tries to open the connection. The connection string is specified but it’s not used: it crashes before that inside the open method of the NpgsqlConnection… There’s little code so it’s easy to follow.
Hopefully it sheds some light what’s going on and what to do to fix it (wherever that is, my code, your code, some config file… )
Npgsql_3886Repro.zip