parzivail/SGP.NET

Invalid format exception issue

Gedd18 opened this issue · 5 comments

Hello
I try to load some TLE data from file and the application stop with an "invalid format exception".
It seems that some parse function need "CultureInfo.InvariantCulture" as second parameter.
It's clear that the exception is fired on system where the '.' is not the decimal separator.

The probleme occurs when loading some LTE data but it can be present in other part of code.
A scan on all function with culture parameter or format provider may be usefull.

Out of curiosity, where are you getting your TLEs? Do you mind sharing the TLE itself?

I was unaware that the standard accounted for regional differences. I'll look into a patch.

Edit: Sorry, didn't mean to immediately close it.

The TLE data were from wikipedia, fr and en.
Also from link on wiki page like CelesTrak
Don't worry about closing issue on your project ! ;o)

Edit : You can find TLE data here : Celestrack NORAD elements

Hello
The problem is in file TLE.cs at lines 337 and 370;

private static void ExtractDouble(string str, int pointPos, out double val)
{
    ...
    val = double.Parse(str); //--> double.Parse(str, CultureInfo, InvariantCulture);
}

private static void ExtractExponential(string str, out double val)
{
    ...
    val = (double) decimal.Parse(correctedString, NumberStyles.Float);
    // --> val = (double) decimal.Parse(correctedString, NumberStyles.Float, CultureInfo, InvariantCulture);
    ...
}

Some other string.Format and parse method can be concerned

Ah, I more completely understand the issue now. I was under the impression that your TLEs contained commas as the decimal separator, not that your system expected them. I was doing research into multicultural decimal formatting until I re-read the issue and I agree this is the best way to fix it.

Released on Nuget in 1.0.4