RoboSharp
RoboSharp copied to clipboard
"The input string 'dddd,ddd' was not in a correct format" exception on version 1.4.2 and higher
Hello
I was using robosharp 1.3.5 with the following code and it was working fine. I tried to update to the latest version and i get the following exception:
[15:28:39 ERR] One or more errors occurred. (The input string '74567.813' was not in a correct format.)
at RoboSharp.RoboCommand.<>c__DisplayClass117_0.<GetRoboCopyTask>b__1(Task continuation)
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
at RoboSharp.RoboCommand.StartAsync(String domain, String username, String password)
at Builder.Helpers.Tools.CopyDirectory(String sourcePath, String destPath, Boolean mirror) in D:\dev\Builder\Builder\Helpers\Tools.cs:line 126
I tried switching version until it works again and it seems the issue comes from version 1.4.2
Here's the code i'm using to call robosharp:
RoboCommand cmd = new();
cmd.CopyOptions.Source = sourcePath;
cmd.CopyOptions.Destination = destPath;
cmd.CopyOptions.CopySubdirectories = true;
cmd.CopyOptions.EnableRestartMode = true;
cmd.CopyOptions.MultiThreadedCopiesCount = Environment.ProcessorCount;
cmd.RetryOptions.RetryCount = 5;
cmd.RetryOptions.RetryWaitTime = 5;
cmd.RetryOptions.WaitForSharenames = true;
if (mirror)
{
cmd.CopyOptions.Mirror = true;
}
else
{
cmd.CopyOptions.EnableRestartModeWithBackupFallback = true;
}
RoboCopyResults results = await cmd.StartAsync();
Environment.ProcessorCount is usually 20 mirror is set to true in this case
Any clue on what could be the issue?
Might be related to 7b53e856c6180b3bcfcc266d2c5bdbdf4475c8ba ?
If it may help, regional format in windows is France in my case
I agree with your find, thanks for pinpointing it. Can you provide an example of the expected output for your region?
This was changed due to this issue in an attempt to sanitize it. https://github.com/tjscience/RoboSharp/issues/189#issuecomment-1999931915
I forgot to force the parse using the Invariant culture though, which is why you discovered the bug.
I believe the solution is this :
match = pattern.Match(line2);
if (match.Success)
{
res.MegaBytesPerMin = decimal.Parse(sanitizeMB(match.Value), NumberFormatInfo.InvariantInfo);
}
Can you post an example of summary lines for us to include in a unit test ?
Velocità: 257.555.063 Byte/sec.
Velocità: 14737,419 MB/min.
I'm only asking because I noticed that the France culture settings use a space for the number group separator, and want to ensure that it won't break if a number like this comes up : 12 1234,34
(which may not even be detected by the regex)
Here it is!
Alright, just an update. While I've been working on the other PR, I've toyed with this as well.
Once #207 is integrated, I have a slew of changes to implement here as part of a larger regex review to try and integrate the new .net7+ regex source generator, which should provide improved performance for newer targets.
But the fix for this will use some of the new string builder extensions during the sanitizing of the value. But there is a fix ready.
Excellent work!!
@NephChevsky - #209 should fix your issue, please review when you get a chance.