1

I use CS-Script to compile code at runtime. I do this like follow and read the generated Errors and Warnings after out of the ComipilingHistory:

var eval = CSScript.Evaluator;
var assembly = eval.CompileCode(code);

if (CSScript.CompilingHistory.Any()) {
   foreach (var err in CSScript.CompilingHistory.Last().Value.Result.Errors.Cast<CompilerError>()) {
      this.AddValidationResult(err, codeFile);
   }
}

The Problem is now, that I get german Messages for warnings. But I need the english ones. I work on a Machine with German Language. But Visual Studio is installed in english and when I compile the Code in Visual Studio, I will get english messages.

How can I configure, that CS-Script is also showing english Warnings and Errors?

Edit: I have now created a small sample to reproduce my problem:

System.Globalization.CultureInfo.DefaultThreadCurrentCulture = new System.Globalization.CultureInfo("en-US");
System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = new System.Globalization.CultureInfo("en-US");


Microsoft.CSharp.CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters compilerparams = new CompilerParameters();
compilerparams.GenerateInMemory = false;
CompilerResults results = provider.CompileAssemblyFromSource(compilerparams, "this generates errors");

Now, I the results, there is the following error:

"Ein Namespace kann nicht direkt Member, wie z.B. Felder oder Methoden, enthalten."

My problem is now, that this message is in german. I should it get in english.

BennoDual
  • 5,865
  • 15
  • 67
  • 153
  • Execute that code in a separate thread with the culture (not UI culture) set to en-US (or temporary change `AppDomain` culture to en-US but...it works only if your code is strictly single-threaded otherwise also your application will be affected) – Adriano Repetti May 03 '18 at 12:03
  • @AdrianoRepetti - Thanks for your answer. I have tried to set `Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");` and second to set additional `Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");` but with no success. – BennoDual May 03 '18 at 12:23
  • It might be that it creates more threads (which aren't affected by that). Well..I'm just guessing without browsing the source code. Does it make any difference if you change it at `AppDomain` level? – Adriano Repetti May 04 '18 at 09:32
  • I have now tried this: `System.Globalization.CultureInfo.DefaultThreadCurrentCulture = new System.Globalization.CultureInfo("en-US");` and `System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = new System.Globalization.CultureInfo("en-US");` - but still with no success. – BennoDual May 17 '18 at 08:04

0 Answers0