Search code examples
c#localeautofacioc-containerautofac-configuration

How to define default Autofac locale used when parsing json/xml configuration


I am trying to configure autofac using xml configuration but run into problems with locale. One of the component that I am trying to register needs double parameter which on my local system has format xxx,yyy - using comma as decimal separator. The other system that I have to use uses dot as a decimal separator. Is there a way how to force autofac to ignore locale settings and only parse numbers with dot as decimal separator?

This configuration

<?xml version="1.0" encoding="utf-8" ?>
<autofac>
  <components name="0">
    <type>Geometry.SomeRule, Geometry</type>
    <services name="0" type="Geometry.IValidationRule, Geometry" />
    <parameters>
      <min>3.048</min>
      <max>4.572</max>
    </parameters>
  </components>
</autofac>

throws

Autofac.Core.DependencyResolutionException: 'An exception was thrown while activating IValidationRule[] -> SomeRule.'
Inner exceptions: Exception: 3,048 is not a valid value for Double.

If I use comma registration works on my device, but does not on the other.

I am able to overcome the issue by setting CurrentThread.CurrentCulture during registration and container building but it does not seems to be a correct solution to me.


Solution

  • It appears you've found a bug. The TypeManipulation code that converts uses the implicit current culture rather than providing a culture. That isn't something that can be overridden.

    I've filed an issue on your behalf.