View Full Version : Problem with Introduction when using MultiThreading
Hi,
I've a problem when using the introduction feature from another thread than the main one.
If this sample code is called from the main thread it work well :
object _Component;
_Component = m_Context.GetObject("SomeComponent");
ProxyFactory factory = new ProxyFactory(_Component);
factory.ExposeProxy = true;
factory.ProxyTargetType = true;
factory.Target = _Component;
factory.AddIntroduction(new ClassToIntroduceAdvisor());
Object _proxy = factory.GetProxy();
((IClassToIntroduce)_proxy).Data1 = "some text";
((IClassToIntroduce)_proxy).Data2 = 1234;
but if I call it from a new thread if failed at:
((IClassToIntroduce)_proxy).Data1 = "some text"; with the System.NullReferenceException.
It look like if a introduction have been done on some thread it's not possible
to do it again on a another thread.
Could someone help me understanding this problem ?
I can send a little demo VS projet if needed.
Thanks
Yann.
Bruno Baia
07-21-2006, 10:46 AM
Hi Yann,
It can be related to this issue :
http://opensource.atlassian.com/projects/spring/browse/SPRNET-340
Can you try what Aleksei proposed ?
-Bruno
Hi Bruno,
Thank you for your response.
I've tried what Aleksei has proposed in the link you send but I'm not sure to understand correctly and exactly what to do...
If I add IDictionary _targetMethods = new Hashtable() in BuildProxy then I got a new error (NullReferenceException) on "Object _proxy = factory.GetProxy()" in my previous code snippet.
Aleksei said to "move" IDictionary _targetMethods = new Hashtable() in BuildProxy() but _targetMethods is used in other methods so it's seems to me that we could not "move" this line of code...
I must admit that all this is a little unclear for me ...
Yann.
Aleksei Kachanov
07-24-2006, 09:21 AM
Sorry, I not clear explain solution.
You should pass __targetMethods in other methods from BuildProxy()
Example
// implement interfaces
foreach (Type intf in advised.Interfaces)
{
object target = advised.InterfaceMap[intf];
if (target == null)
{
ImplementTargetInterface(typeBuilder, intf, advised.TargetSource.TargetType, _targetMethods);
}
else if (target is IIntroductionAdvisor)
{
ImplementIntroductionInterface(typeBuilder, intf, advised.IndexOf((IIntroductionAdvisor)target), ((IIntroductionAdvisor)target).Advice.GetType(), _targetMethods);
}
}
protected virtual void ImplementTargetInterface(TypeBuilder typeBuilder, Type intf, Type targetType, IDictionary _targetMethods)
...
protected virtual void ImplementIntroductionInterface(TypeBuilder typeBuilder, Type intf, int index, Type introductionType, IDictionary _targetMethods)
...
protected virtual void ImplementMethods(TypeBuilder typeBuilder, IProxyMethodBuilder methodBuilder, InterfaceMapping mapping, IDictionary _targetMethods)
Hi Aleksei,
Thank you for your response.
Looking at the problem now, your explanation was clear but my extrapolation capabilities was not ;)
I've done the modifications now but I still have the same behavior that I've described in my first post. The same System.NullReferenceException when calling "((IClassToIntroduce)_proxy).Data1 = "some text";".
I've attach to this post the sample code I use for my tests, may be it could help solving this problem...
Yann.
Aleksei Kachanov
07-24-2006, 12:52 PM
Your problem is not related to http://opensource.atlassian.com/projects/spring/browse/SPRNET-340
Bruno Baia
07-24-2006, 02:28 PM
Hi,
Thks for your help Aleksei.
As you said, it seems to be not related to the SPRNET-340 issue.
Yann, try changing the StaticAttribute to ContexAttribute for the static field "_proxyStack" in the class Spring.Aop.Framework.AopContext.
-Bruno
Hi,
Thank you for you help, It seem to work now on my sample app. I will try this on the real project in some weeks.
Thanks a lot again.
Yann.
Bruno Baia
09-01-2006, 11:31 PM
Hi,
This issue has been resolved, retrieve the next latest nightly build (http://www.springframework.net/downloads/nightly/) to get the fix.
-Bruno
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.