cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Neo4j .NET Hello World example not working with the newest version of Neo4j driver

It seems like the published Hello World Example does not work with the most recent version of the .NET driver - when I put this code into Visual Studio after downloading the most recent version from nuGet, it has errors: https://neo4j.com/docs/driver-manual/current/get-started/#driver-get-started-hello-world-example.
Could anyone help me out with getting this working? I was hoping to use it as a baseline to build my own program.

1 REPLY 1

The example will work if you use the Neo4j.Driver.Simple nuget package - once you've got used to that you can switch to the async version if you want, which would be something like this:

public class HelloWorldExample
{
	private readonly IDriver _driver;

	public HelloWorldExample(string uri, string user, string password)
	{
		_driver = GraphDatabase.Driver(uri, AuthTokens.Basic(user, password));
	}

	public async Task PrintGreeting(string message)
	{
		var session = _driver.AsyncSession();
		var greeting = session.WriteTransactionAsync(async tx =>
		{
			var result = await tx.RunAsync("CREATE (a:Greeting) " +
								"SET a.message = $message " +
								"RETURN a.message + ', from node ' + id(a)",
				new { message });
			return (await result.SingleAsync())[0].As<string>();
		});
		Console.WriteLine(greeting);
		await session.CloseAsync();
	}
	
	public static async Task Main()
	{
		var greeter = new HelloWorldExample("bolt://localhost:7687", "neo4j", "neo");
		await greeter.PrintGreeting("hello, world");
	}
}