Last post Oct 23, 2008 12:16 PM by bigtower
Oct 06, 2006 06:39 AM|rstrahl|LINK
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,
object value = this.ResourceManager.GetObject(resourceKey,culture);
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 --
Oct 07, 2006 03:15 AM|vivek_iit|LINK
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?
Oct 07, 2006 05:01 AM|rstrahl|LINK
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:
With the solution in the comments.
Oct 23, 2008 12:16 PM|bigtower|LINK
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.