Skip to main content

Microsoft Silverlight

Answered Question Setting CurrentThread.CurrentCulture gives set_CurrentCulture errorRSS Feed

(0)

jpsscott
jpsscott

Member

Member

51 points

84 Posts

Setting CurrentThread.CurrentCulture gives set_CurrentCulture error

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 Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Re: Setting CurrentThread.CurrentCulture gives set_CurrentCulture error

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...

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

jpsscott
jpsscott

Member

Member

51 points

84 Posts

Re: Setting CurrentThread.CurrentCulture gives set_CurrentCulture error

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.

 Thanks,

 James

Sergey Volk MSFT
Sergey V...

Participant

Participant

788 points

98 Posts

Microsoft

Re: Setting CurrentThread.CurrentCulture gives set_CurrentCulture error

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.

If this answers your question, please click on "Mark as Answer" on this post.

jpsscott
jpsscott

Member

Member

51 points

84 Posts

Re: Setting CurrentThread.CurrentCulture gives set_CurrentCulture error

Thanks,

 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?

Thanks,

James

Sergey Volk MSFT
Sergey V...

Participant

Participant

788 points

98 Posts

Microsoft
Answered Question

Re: Setting CurrentThread.CurrentCulture gives set_CurrentCulture error

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.

If this answers your question, please click on "Mark as Answer" on this post.

jpsscott
jpsscott

Member

Member

51 points

84 Posts

Re: Setting CurrentThread.CurrentCulture gives set_CurrentCulture error

No problem at all.  Really appreciate the answer!

 James

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities