View previous topic :: View next topic |
Author |
Message |
gunters63
Joined: 25 Jan 2011 Posts: 21
|
Posted: Wed May 25, 2011 11:18 am Post subject: Problem using WPF Resx extension in styles |
|
|
I have some strange problems here in my WPF application in that the initial resource lookup of all the ResX markups works fine, but on-the-fly language switching didn't work on some.
I debugged the Infralution.Localization.WPF dll and noticed that some of the markup extension objects were wiped out in MarkupExtensionManager.CleanupInactiveExtensions() because the target weak reference was not alive anymore. Those were exactly the ResX markups where on-the-fly language switching stopped working.
After a close look at my ResX usage pattern i noticed that all uses INSIDE a WPF style were wiped this way, all the others were OK.
I patched the Localization.dll to return IsTargetAlive=true everytime (not checking the weak reference anymore) and now language selection works flawlessly for all ResX markups.
Is there probably a problem with the weak reference cleanup if you use ResX inside styles?
Regards,
Gunter |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed May 25, 2011 11:26 pm Post subject: |
|
|
Is there a chance you could put together a small project that illustrates the problem (maybe modify the WPF sample project) and send a zipped copy to support@infralution.com. That would help us track down the issue. _________________ Infralution Support |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Fri May 27, 2011 8:01 am Post subject: |
|
|
Thanks for the sample project - it helped find what was a fairly subtle problem. While your workaround fixes the immediate issue it would result in a memory leak where the ResxExtension objects are never disposed even after the window is. The correct fix is to change ManagedMarkupExtension.IsTargetAlive to the following:
Code: | /// <summary>
/// Is an associated target still alive ie not garbage collected
/// </summary>
public bool IsTargetAlive
{
get
{
// for normal elements the _targetObjects.Count will always be 1
// for templates the Count may be zero if this method is called
// in the middle of window elaboration after the template has been
// instantiated but before the elements that use it have been. In
// this case return true so that we don't unhook the extension
// prematurely
//
if (_targetObjects.Count == 0)
return true;
// otherwise just check whether the referenced target(s) are alive
//
foreach (WeakReference reference in _targetObjects)
{
if (reference.IsAlive) return true;
}
return false;
}
}
|
We will fix the source code on Code Project and the compiled version of the assembly in the release as soon as possible. _________________ Infralution Support |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon May 30, 2011 5:53 am Post subject: |
|
|
Version 2.3.12 of Globalizer.NET has now been released and fixes this issue. _________________ Infralution Support |
|
Back to top |
|
|
|