neo4j / neo4j-dotnet-driver

Neo4j Bolt driver for .NET
Apache License 2.0
232 stars 69 forks source link

Issues with .net framework 4.7.2. #614

Closed Thypari closed 2 years ago

Thypari commented 2 years ago

Hey,

I migrated from neo4j 3.5.20 to 4.4.6. The db itself runs fine and is accessible via browser but when trying to connect with the neo4j dotnet driver I get the following exception:

Neo4j.Driver.ServiceUnavailableException: Failed after retried for 6 times in 30000ms. Make sure that your database is online and retry again. ---> System.AggregateException: One or more errors occurred. ---> Neo4j.Driver.ServiceUnavailableException: Connection with the server breaks due to IOException: Failed to connect to server 'bolt://{redacted}:7687/' via IP addresses'[{redacted}]' at port '7687'. Please ensure that your database is listening on the correct host and port and that you have compatible encryption settings both on Neo4j server and driver. Note that the default encryption setting has changed in Neo4j 4.0. ---> System.IO.IOException: Failed to connect to server 'bolt://{redacted}:7687/' via IP addresses'[{redacted}]' at port '7687'. ---> System.AggregateException: One or more errors occurred. ---> System.IO.IOException: Failed to connect to server 'bolt://{redacted}:7687/' via IP address {redacted}: Could not load file or assembly 'System.Net.Sockets, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Sockets, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Sockets, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I am using .net framework 4.7.2 and the latest neo4j dotnet driver nuget package 4.4.0. This is the connection code:

GraphDatabase.Driver("bolt://" + GetComputerFQDN() + ":7687", AuthTokens.Basic("{redacted}", "{redacted}"),
                configBuilder => configBuilder
                    .WithEncryptionLevel(EncryptionLevel.None)
                    .WithConnectionTimeout(TimeSpan.FromSeconds(5D))
                    .WithConnectionIdleTimeout(TimeSpan.FromMilliseconds(-1D))
                    .WithMaxConnectionPoolSize(500)
                    .WithConnectionAcquisitionTimeout(TimeSpan.FromMinutes(1)));

This is the part which I don't understand:

Could not load file or assembly 'System.Net.Sockets, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

System.Net.Sockets should be provided by .Net Framework? Nonetheless, I couldn't even find anything about a 4.1.1.0 version. It also tries to load 4.0.0.0, but still fails. It seems .Net Frameowrk 4.7.2 uses System.Net.Sockets 4.2.0.0:

https://i.imgur.com/NZ5rZ2Z.png

EDIT: .net standard 2.0 seems to use System.Net.Sockets 4.1.2.0?

thelonelyvulpes commented 2 years ago

Hi @Thypari.

I can recreate the issue, I'll look into it, and get back to you soon.

thanks

thelonelyvulpes commented 2 years ago

Hi @Thypari.

I managed to recreate the issue by setting my .NET framework to 4.7.1. doing a build then going to 4.7.2 then doing a build, when I did that I got the same error as yourself. while on 4.7.2 I did a solution clean, restore and build it went back to working, could you try that?

Thypari commented 2 years ago

while on 4.7.2 I did a solution clean, restore and build it went back to working, could you try that?

I tried cleaning, restore and build. Unfortunately I get the same error. I will try to delete all the binfolders and .vs folders next. Thank you for your help, I'll let you know if this will resolve my issue.

EDIT: Can you share some information with me? When you were able to solve the issue, did the System.Net.Sockets.dll exist in your debug folder after building?

Thypari commented 2 years ago

I failed to solve the issue unfortunately: I tried:

Here is some additional information. I am building x64 explicitly. I am using VS 2019 Pro.

Any ideas what I can try next?

EDIT: Can you share some information with me? When you were able to solve the issue, did the System.Net.Sockets.dll exist in your debug folder after building? I've found some bug reports of VS 2019 Pro with the exact same issue where .standard dlls were not correctly copied to the debug folder.

Thypari commented 2 years ago

Okay I was finally able to fix it. In one of my 200 projects in this solution was a binding redirect for system.net.sockets to version 4.1.1.0. No idea how this was introduced... After removing it, I could connect to the db!

thelonelyvulpes commented 2 years ago

@Thypari I'm glad to hear, binding redirects were going to be my next suggestion.