Page view counter

IResourceProvider.GetObject() - Culture is always Invariant

Last post 10-23-2008 12:16 PM by bigtower. 3 replies.

Sort Posts:

  • IResourceProvider.GetObject() - Culture is always Invariant

    10-06-2006, 6:39 AM
    • Loading...
    • rstrahl
    • Joined on 08-20-2003, 1:08 PM
    • Paia, Hawaii
    • Posts 277
    • Points 1,431
    • ASPInsiders
      TrustedFriends-MVPs

    So I've implement a custom ResourceProvider and ResourceManager. It's actually working correctly, however, I'm a little confused why the the IResourceProvider.GetObject() method always receives an Invariant culture.

    object IResourceProvider.GetObject(string resourceKey, CultureInfo culture)

    {

    object value = this.ResourceManager.GetObject(resourceKey,culture);

    return value;

    }

    On a page that has its UICulture set I can see the GetObject method firing twice for each object (looks like once for precompilation and once for the actual page access. But in both cases the culture is Invariant even though the page's culture is specific to the user.

    It all works anyway - so it looks like the ResourceManager implementation manages to handle the Resource Fallback automatically using the CurrentUICulture instead of the Invariant Culture passed in. Which strikes me as really odd. If I ask the resource manager for the Invariant culture - it should give me that, but instead it's returning the currentUI culture if there's an entry for it.

    What the heck is going on here?

    I have no code that retrieves this data on its own - I simply have a ResourceManager and ResourceReader implementation that provides a ResourceSet and this obviously works since otherwise the data is being fed properly.The resource reader and manager are managing all of this, but what's the point of the culture parameter if the culture is not actually passed?

    +++ Rick --

     

     

     

    Rick Strahl
    West Wind Technologies
    Making waves on the Web
    www.west-wind.com/weblog
  • Re: IResourceProvider.GetObject() - Culture is always Invariant

    10-07-2006, 3:15 AM
    • Loading...
    • vivek_iit
    • Joined on 06-18-2006, 6:13 PM
    • New Delhi
    • Posts 3,125
    • Points 17,294
    • TrustedFriends-MVPs

    Hi Rick,

    I am not sure but may be thread agility be one of the issues. Is it possible for you to paste some sample trimmed down version of your code here so that I can also try and figure out what's happening behind the scenes?

    Regards,

    Vivek

    CodeASP.NET Community

    Please mark the most helpful reply/replies as "Answer".
  • Re: IResourceProvider.GetObject() - Culture is always Invariant

    10-07-2006, 5:01 AM
    Answer
    • Loading...
    • rstrahl
    • Joined on 08-20-2003, 1:08 PM
    • Paia, Hawaii
    • Posts 277
    • Points 1,431
    • ASPInsiders
      TrustedFriends-MVPs

     

    It turns out I had a problem with the code in GetResourceKeys() which I lifted from DefaultImplictResourceProvider(). The code seemed to work but something must have been wrong with the returned keys as GetObject never did get called.

     I posted more info on this here:

    http://www.west-wind.com/weblog/posts/4726.aspx

     With the solution in the comments.

    Rick Strahl
    West Wind Technologies
    Making waves on the Web
    www.west-wind.com/weblog
  • Re: IResourceProvider.GetObject() - Culture is always Invariant

    10-23-2008, 12:16 PM
    • Loading...
    • bigtower
    • Joined on 10-15-2008, 9:59 AM
    • Posts 3
    • Points 2

    Hi

    Just wrote a simple "hello world" custom provider, following Rick Strahl's excellent paper.

    However, as in the original post, Getobject() seems to be called twice, once with culture = invariant, and then a second time with culture= nothing, although my page culture and UiCulture are both "es-es". Why is Getobject  called twice and why is the culture argument an incorrect value both times?

     As in Rick Strahl's code, if culture= nothing then I just use the CurrentUiCulture in Getobject(). This solves the problem, and the final page gets the correct localized string . But the questions still remain.

     Thanks a bunch.

     

Page 1 of 1 (4 items)