Uploaded image for project: 'Spring.NET'
  1. Spring.NET
  2. SPRNET-1495

double parsing for constructor-arg is culture sensitive

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.3.2
    • Fix Version/s: FUTURES
    • Component/s: Spring-NET-CORE
    • Labels:
      None

      Description

      My spring.config contains the following part:

      <object id="SomeNamespace.Api.ISomething"
      type="SomeNamespace.Impl.Something, SomeNamespace.Impl">
      <constructor-arg name="scoreThreshold">
      <value>0.0</value>
      </constructor-arg>
      </object>

      The first argument of the "Something" constructor is a double.
      When launching my application, I get the following exception (my visual studio is configured to pop up even caught exceptions Debug>Exceptions>Break when a "CLR exception" is Thrown):

      System.Exception occurred
      Message=0.0 is not a valid value for Double.
      Source=System
      StackTrace:
      at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
      at System.ComponentModel.TypeConverter.ConvertFrom(Object value)
      at Spring.Core.TypeConversion.TypeConversionUtils.ConvertValueIfNecessary(Type requiredType, Object newValue, String propertyName) in c:_prj\spring-net\trunk\src\Spring\Spring.Core\Core\TypeConversion\TypeConversionUtils.cs:line 129
      InnerException: System.FormatException
      Message=Input string was not in a correct format.
      Source=mscorlib
      StackTrace:
      at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
      at System.ComponentModel.DoubleConverter.FromString(String value, NumberFormatInfo formatInfo)
      at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)

      It seems that it is using the culture of my computer (which happens to be French) to parse the value, and gets stuck because it expects a comma (,) as the decimal separator.

      Is there a way to set the culture used to parse constructor arguments? What is the failback when this exception happens, does it use default(double) as the value? Or does it parse it with InvariantCulture in a second pass?

      I wouldn't want to let go of my "show Exceptions thrown" policy in visual studio as it helps me spot useful bugs.

        Attachments

          Activity

            People

            Assignee:
            sbohlen Steve Bohlen
            Reporter:
            lyin Laurent Yin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated: