How to run CSharpScript scripts as invariant culture?

-2

I have a small experimental WPF, (.net5), app, (image below), to play with CSharpScript that takes in a string wherever the placeholder [input] is.

I'm running on a Norwegian locale and so the code refuses to handle "." as decimal separator, and requires "," in stead. This is not acceptable, and need to run this in an invariant culture.

I found the relevant docs, (link below), for it and tried to implement specifying invariant culture in the csproj, (full xml below), but then I only get an exception when I click the input value textbox, (see exception below). If I don't specify it refuses to parse "1.0" as One-DecimalSeperator-Zero, and gives this exception message:
Input string was not in a correct format.

So if I can't set it on project-level, how can I set it globally??

Docs:
https://docs.microsoft.com/en-us/dotnet/core/run-time-config/globalization#examples

Exception when clicking the the input textbox, (removed about half of the lines in the stacktrace for brevity):

System.Globalization.CultureNotFoundException
  HResult=0x80070057
  Message=Culture is not supported.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Globalization.CultureData.GetCultureData(Int32 culture, Boolean bUseUserOverride)
   at System.Globalization.CultureInfo..ctor(Int32 culture, Boolean useUserOverride)
   at System.Globalization.CultureInfo..ctor(Int32 culture)
   at System.Windows.Input.InputLanguageSource.get_CurrentInputLanguage()
   at System.Windows.Input.InputLanguageManager.get_CurrentInputLanguage()
   at System.Windows.Documents.TextSelection.EnsureCaret(Boolean isBlinkEnabled, Boolean isSelectionActive, CaretScrollMethod scrollMethod)
   at System.Windows.Documents.TextSelection.System.Windows.Documents.ITextSelection.UpdateCaretAndHighlight()
   at System.Windows.Documents.TextEditor.OnGotKeyboardFocus(Object sender, KeyboardFocusChangedEventArgs e)
   at System.Windows.Controls.Primitives.TextBoxBase.OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
   at System.Windows.UIElement.OnGotKeyboardFocusThunk(Object sender, KeyboardFocusChangedEventArgs e)
   at System.Windows.Input.KeyboardFocusChangedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.KeyboardDevice.ChangeFocus(DependencyObject focus, Int32 timestamp)
   at System.Windows.Input.KeyboardDevice.TryChangeFocus(DependencyObject newFocus, IKeyboardInputProvider keyboardInputProvider, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
   at System.Windows.Input.KeyboardDevice.Focus(DependencyObject focus, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
   at System.Windows.Input.KeyboardDevice.Focus(IInputElement element)
   at System.Windows.UIElement.Focus()
...

App image:

enter image description here

.csproj:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net5.0-windows</TargetFramework>
        <LangVersion>9.0</LangVersion>
        <Nullable>enable</Nullable>
        <UseWPF>true</UseWPF>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.CodeAnalysis.Scripting" Version="3.8.0-5.final" />
    </ItemGroup>

    <PropertyGroup>
        <InvariantGlobalization>true</InvariantGlobalization>
    </PropertyGroup>
</Project>

c#
wpf
globalization
csproj
csharpscript

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0