Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Culture specific errors from Roslyn Compilation

I am trying to compile some code which has incorrect syntax using the Roslyn Emit Api. The thread compiling the code has Culture set to "fr-Fr" but the diagnostic messages I obtain from the Roslyn api are in English. e.g.

error BC30037: Character is not valid.

I am wondering if there is a way to get the error messages in the thread specific culture. Same happens with codeDom too.

like image 399
Anoop Avatar asked Jan 25 '26 23:01

Anoop


1 Answers

This is probably not a viable answer, but I'll post it anyway in case it's of interest.

The Roslyn compiler is open source, so it can be modified, and in this way the error messages can be changed from English to French, or whatever. Just be aware that Roslyn is a huge program, and rebuilding it is not all that easy, at least in my experience.

I've written a few blog articles about my experiences with modifying Roslyn. My latest modification included adding a new error message - that's how I happened to find this question.

https://renniestechblog.com/information/33-modifying-roslyn-step-1-initial-test

https://renniestechblog.com/information/39-modifying-roslyn-step-6-fake-attribute-yacksserialization

It may even be possible to make Roslyn multilingual, by adding an additional CSharpResources.fr-FR.resx file to the project, and letting ResourceManager automatically choose the correct .resx file. This definitely works with .Net Framework WinForms projects, but I don't know if this functionality has been preserved in the new .Net Standard format.

like image 182
RenniePet Avatar answered Jan 29 '26 19:01

RenniePet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!