Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem using WPF Resx extension in styles

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Globalizer Support
View previous topic :: View next topic  
Author Message
gunters63



Joined: 25 Jan 2011
Posts: 21

PostPosted: Wed May 25, 2011 11:18 am    Post subject: Problem using WPF Resx extension in styles Reply with quote

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
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed May 25, 2011 11:26 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri May 27, 2011 8:01 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon May 30, 2011 5:53 am    Post subject: Reply with quote

Version 2.3.12 of Globalizer.NET has now been released and fixes this issue.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Globalizer Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group