xsharp.eu • System.TypeInitializationException: 'The type initializer for 'XSharp.ConversionHelpers' threw an exception.'
Page 1 of 1

System.TypeInitializationException: 'The type initializer for 'XSharp.ConversionHelpers' threw an exception.'

Posted: Mon Oct 02, 2023 2:25 pm
by baramuse
Hi, I've recently hit that exception when working on a asp.net core implementation of our webservices.
The culprit is

Code: Select all

nValue := Val( "100.00" )
but also happens in NTrim function for example.

The xsharp lib referenced by the asp.net core website has been compiled using an sdk project type targeting .net8 as well.

System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'XSharp.ConversionHelpers' threw an exception.
Source=XSharp.RT
StackTrace:
at XSharp.RT.Functions._VOVal(String cNumber)
at XSharp.RT.Functions.Val(String cNumber)
at PIniFile.ReadReal8(String cEntry, Double nDefault) in REDACTED
This exception was originally thrown at this call stack:
[External Code]

Inner Exception 1:
CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
en-US is an invalid culture identifier.

Any hint ?

Regards.

Re: System.TypeInitializationException: 'The type initializer for 'XSharp.ConversionHelpers' threw an exception.'

Posted: Mon Oct 02, 2023 3:27 pm
by baramuse
Ok I think I found a fix, in the asp.net-core project file, I had to change

Code: Select all

    <InvariantGlobalization>true</InvariantGlobalization>
to

Code: Select all

    <InvariantGlobalization>false</InvariantGlobalization>
I don't know why it ws set to true by default, as the default value is false (if you don't explicitely set it to true...)