I want to catch exceptions that occurs when I try to connect to my neo4j database using the Neo4jClient.dll. If the database is offline I get the following error: "an exception of type 'System.AggregateException' occurred in mscorlib.dll but was not handled in user code." My catch-block is never reached.
This is my code:
class Neo4JConnector
{
private static GraphClient client = null;
public Neo4JConnector(IniConfigSource configSource)
{
if (client == null)
{
client = new GraphClient(new Uri(configSource.Configs["Configuration"].Get("Neo4jUrl")));
try
{
client.Connect();
}
catch (Exception ex)
{
Console.WriteLine("Cannot connect"); // never reached :(
}
Then I tried to use the "extern" modifier with this code:
class Neo4JConnector
{
private static GraphClient client = null;
[DllImport("Neo4jClient.dll", EntryPoint="Connect")]
static extern void Connect();
public Neo4JConnector(IniConfigSource configSource)
{
if (client == null)
{
client = new GraphClient(new Uri(configSource.Configs["Configuration"].Get("Neo4jUrl")));
try
{
Connect();
}
catch (Exception ex)
{
Console.WriteLine("Cannot connect");
}
}
But all I get is an Exception that says "[System.EntryPointNotFoundException] = {"Unable to find an entry point named 'Connect' in DLL 'Neo4jClient.dll'.":""}"
This is how the signature looks like in Neo4jClient.dll
public virtual void Connect();
What's wrong with my code? Is there a better way to catch external exceptions? Please help :(