C
C#11mo ago
HAHA

System.UriFormatException: 'Invalid URI: The hostname could not be parsed.'

using RabbitMQ.Client;
using System;

namespace RabbitMQ.Implementations
{
public abstract class RabbitMQClient : IDisposable
{
protected IConnection _connection;
protected IModel _channel;

public RabbitMQClient()
{
var username = Environment.GetEnvironmentVariable("AMQP_USERNAME") ?? throw new Exception("Env var AMQP_USERNAME is not defined.");
var password = Environment.GetEnvironmentVariable("AMQP_PASSWORD") ?? throw new Exception("Env var AMQP_PASSWORD is not defined.");
var host = Environment.GetEnvironmentVariable("AMQP_HOST") ?? throw new Exception("Env var AMQP_HOST is not defined.");

var factory = new ConnectionFactory
{
Uri = new Uri($"amqp://{username}:{password}@{host}")
};

_connection = factory.CreateConnection();
_channel = _connection.CreateModel();
}

public void Dispose()
{
_connection.Dispose();
_channel.Dispose();
}
}
}
using RabbitMQ.Client;
using System;

namespace RabbitMQ.Implementations
{
public abstract class RabbitMQClient : IDisposable
{
protected IConnection _connection;
protected IModel _channel;

public RabbitMQClient()
{
var username = Environment.GetEnvironmentVariable("AMQP_USERNAME") ?? throw new Exception("Env var AMQP_USERNAME is not defined.");
var password = Environment.GetEnvironmentVariable("AMQP_PASSWORD") ?? throw new Exception("Env var AMQP_PASSWORD is not defined.");
var host = Environment.GetEnvironmentVariable("AMQP_HOST") ?? throw new Exception("Env var AMQP_HOST is not defined.");

var factory = new ConnectionFactory
{
Uri = new Uri($"amqp://{username}:{password}@{host}")
};

_connection = factory.CreateConnection();
_channel = _connection.CreateModel();
}

public void Dispose()
{
_connection.Dispose();
_channel.Dispose();
}
}
}
No description
18 Replies
Pobiega
Pobiega11mo ago
And what are your values for those three variables?
HAHA
HAHAOP11mo ago
Let me get them I haven't added a try/catch
Pobiega
Pobiega11mo ago
Don't need one, just set a breakpoint and use the debugger?
HAHA
HAHAOP11mo ago
ok host "10.8.3.85" string
HAHA
HAHAOP11mo ago
No description
HAHA
HAHAOP11mo ago
here in the env variables
Pobiega
Pobiega11mo ago
ah I think the @ fucks you over since your string becomes root:Admin@[email protected]
HAHA
HAHAOP11mo ago
might be the case
Pobiega
Pobiega11mo ago
you'll need to escape it I guess, or change the password
HAHA
HAHAOP11mo ago
Uri = new Uri(@"amqp:/{username}:{password}@{host}")
Uri = new Uri(@"amqp:/{username}:{password}@{host}")
went for this instead minor case of interpolation
Pobiega
Pobiega11mo ago
hm will that work thou? no interpolation there that string will become literally amqp:/{username}:{password}@{host}
HAHA
HAHAOP11mo ago
yeah just noticed that I meant to write that as it is
Uri = new Uri("amqp://root:Admin@[email protected]")
Uri = new Uri("amqp://root:Admin@[email protected]")
Pobiega
Pobiega11mo ago
not sure that will work either thou having 2 @ in that string will be problematic
HAHA
HAHAOP11mo ago
var encodedPassword = Uri.EscapeUriString(password);
var factory = new ConnectionFactory
{
Uri = new Uri($"amqp://{username}:{encodedPassword}@{host}")
};
var encodedPassword = Uri.EscapeUriString(password);
var factory = new ConnectionFactory
{
Uri = new Uri($"amqp://{username}:{encodedPassword}@{host}")
};
did this
Pobiega
Pobiega11mo ago
yep, thats better
HAHA
HAHAOP11mo ago
didnt work
Pobiega
Pobiega11mo ago
rip remove the @ from the password, or find an alternative to using a uri if escaping it wont work
HAHA
HAHAOP11mo ago
that was it it worked for test env thxowo
Want results from more Discord servers?
Add your server