Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Setting CurrentThread.CurrentCulture gives set_CurrentCulture error
6 replies. Latest Post by jpsscott on May 1, 2008.
(0)
jpsscott
Member
51 points
84 Posts
04-11-2008 3:49 PM |
Hi,
When attempting to set the culture of my Silverlight application to a different culture I get this error:
"Attempt to access the method failed: System.Threading.Thread.set_CurrentCulture"
Any changes I try to make inside the culture also result in an exception, or simply do not take.
We have an application where it is extremely important we be able to change the culture on the fly. Is this something that is going to be fixed?
I also would like to know if there is some reason behind this. (I might learn something)
Thanks,
James
Yi-Lun L...
All-Star
25052 points
2,747 Posts
04-14-2008 5:07 AM |
Hello, the setter for CurrentCulture requires special permissions. I don't think you can call it. Unfortunately the localization story is not very good in Beta1. This is one area that our product team is working on. But I can't assure you anything at this time...
04-14-2008 7:04 AM |
Hmmm...
Well hopefully the Silverlight team figures it out. Otherwise I'm going to have to program all my own controls to workaround the fact I can't set the CurrentCulture of the application.
Sergey V...
Participant
788 points
98 Posts
04-29-2008 4:23 PM |
Hi James,
Hopefully our localization story will be much better in Beta 2. There has been some work focused in that direction. But as far as I know you are not supposed to set CurrentCulture directly. Instead you should specify <param name="culture" value="fr-FR"> in your <object> tag when instantiating SL plugin. This will set both Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture in Beta1. In Beta2 you will be able to specify CurrentUICulture separately from CurrentCulture by adding <param name="uiculture" value="en-US"> to <object> tag.
So I would suggest you to try something like:
<object type="application/x-silverlight" style="width:200px; height:200px"> <param name="Source" value="ClientBin/App.xap" /> <param name="culture" value="fr-FR"></object>
But beware that there were some other known issues with localization in SL2 Beta1 (see this thread http://silverlight.net/forums/p/12709/49929.aspx#49929).
I would suggest you to wait for Beta2 before using localization features.
04-30-2008 10:28 AM |
I actually tried this in my app, and a basic test app with nothing in it except the culture setting in object param tag, and neither worked. I triple checked what I was doing and can't possibly imagine what I am doing wrong.
My test app simply consists of setting the culture <param name="culture" value="fr-FR"> as you recommended. From there, my test page puts the value of DateTime.Now.ToLongDateString() into a text block for display. It always comes through in en-US and when I check culture of thread in debug mode its en-US.
Can you please tell me what the heck is going on here?
04-30-2008 7:04 PM |
Oops, you are right. I have just checked with Beta1 bits and setting culture param there doesn't set Thread.CurrentThread.CurrentCulture indeed. Turns out this was added after Beta1 was released to public. In Beta2 setting culture / uiculture params on <object> tag will set Thread.CurrentThread.CurrentCulture / CurrentUICulture respectively, and you will be able to also set culture / uiculture to "auto" and SL will then auto-detect current culture from OS settings. So again, I would suggest you to wait before Beta2 before doing any localization work for SL.
Sorry for the confusion.
05-01-2008 6:48 AM |
No problem at all. Really appreciate the answer!