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

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
baramuse
Posts: 85
Joined: Tue Nov 29, 2022 8:31 am
Location: France

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

Post 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.
User avatar
baramuse
Posts: 85
Joined: Tue Nov 29, 2022 8:31 am
Location: France

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

Post 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...)
Post Reply