Jay Gould Jay Gould - 3 months ago 8
C# Question

Characters added to end of string at run time

I have a

bool
that checks to see if a local web service is available by testing a quick query, if it fails then
StartOSRMService()
is ran.

Config:

Config config = new Config
{
localhostNearest = "C:/path/...",
localhostRoute = "C:/path/...",
processLocation = @"C:/path/...",
WorkingDirectory = @"C:/path/...",
DataSource = "file-latest.osrm"
};


StartOSRMService()

private void StartOSRMService()
{
var startInfo = new ProcessStartInfo(config.processLocation);
startInfo.WorkingDirectory = config.WorkingDirectory;
startInfo.UseShellExecute = false;
startInfo.Arguments = config.DataSource;
Process.Start(startInfo);
}


ServiceAvailable():

public bool ServiceAvailable()
{
string lon = "-0.00000000";
string lat = "51.0000000000";
try
{
WebRequest request = WebRequest.Create($"{config.localhostNearest}{lon},{lat}");
WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
Routing point = new JavaScriptSerializer().Deserialize<Routing>(responseFromServer);
if (point.code == "Ok")
{
return true;
}
StartOSRMService();
return false; // Needed but never executed?
}
catch (Exception)
{
StartOSRMService();
// TODO receive routes?
return false;
}
}


When
StartOSRMService()
is ran, I get this output:

[info] starting up engines, v5.3.0[0m
[info] Threads: 8[0m
[info] IP address: 0.0.0.0[0m


With
[0m
being appended to everything that comes out of the console from this point onwards. This means that if I then send a string through a
request()
, the string has
[0m
appended to it and fails to return a correctly formatted
response()
.

If I run
OSRM
from
CMD
prior to running my application in Visual Studio, I don't have this problem.

Can anybody tell me why the
[0m
might be appearing and how I can get rid of it?

Answer

The solution to this was Console.ResetColor();"