wpf: System.FormatException: 'Unexpected token
- .NET Core Version: 3
- Windows version: 18362.499
- Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
Problem description:
i want to create geometry with geometry.Parse(mystring);
but i get following error
System.FormatException: 'Unexpected token
after some research i found that i can fix problem with this code in app.cs
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
now i have another problem and some of my controls like datepicker not work and get exception
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (6 by maintainers)
Okay, I had a look at the code, and it is a bit more complicated. As @weltkante said,
.ToString(CultureInfo.InvariantCulture)
has no effect on strings, so you don’t need to add that to string variables. However, the double values inarr
will actually always by integer numbers, because it’s split in a bit crazy manner in the geometry animation:https://github.com/ghost1372/HandyControls/blob/8afaf3f921be9990e8014038f4064c5a900807c6/src/Shared/HandyControl_Shared/Media/Animation/GeometryAnimationUsingKeyFrames.cs#L30
We assumed the decimal separators are coming from the double values, but in fact they are in the string values.
For some reason which I can see might be a bit controversial yet consistent with the framework,
Geometry.ToString()
uses current culture to format the string (so it cannot be directly passed to theParse
method). In the light of the above, my previous advice does nothing to mitigate the problem, my apologies. The fix of the formatting problem you are having is to edit the above line to read_keyFrames[0].Value.ToString(CultureInfo.InvariantCulture)
.Note that I get an
IndexOutOfRangeException
anyway but that I guess is something for you to work on.