PolicyInjection & DataBinding, Interface vs. MarshalByRefObject vs. ContextBoundObject

Topics: Policy Injection Application Block
Jul 2, 2008 at 4:53 PM
Hi,

I've started using PolicyInjection and I have a problem with one of my policy wrapped types when I try to use databinding.

I'm using interfaces, so I have a IBasketHelper and a BasketHelper and I am creating my instances using .Wrap (I've tested with .Create and it gives the same results).

IBasketHelper bh = PolicyInjection.Wrap<IBasketHelper>(new BasketHelper(user, basketName))

When I create a List<IBasketHelper> of basket helpers and then bind that list to a gridview, I get  "System.ArgumentException: instance" at the first databinder : <%#DataBinder.Eval(Container.DataItem,"BasketName") %>

If I change my BasketHelper class to inherit from MarshalByRefObject or ContextBoundObject, then the databinding works as expected.

I guess there is some sort of issue with the context because the PolicyInjection is using the remoting proxy.

Can I use PolicyInjection with only interfaces or will I frequently need to inherit from these speccific classes?


Jul 2, 2008 at 6:56 PM
Can you do ((IBasketHelper)Container.DataItem).BasketName instead of using DataBinder.Eval?

Fernando


AndrewSeven wrote:
Hi,

I've started using PolicyInjection and I have a problem with one of my policy wrapped types when I try to use databinding.

I'm using interfaces, so I have a IBasketHelper and a BasketHelper and I am creating my instances using .Wrap (I've tested with .Create and it gives the same results).

IBasketHelper bh = PolicyInjection.Wrap<IBasketHelper>(new BasketHelper(user, basketName))

When I create a List<IBasketHelper> of basket helpers and then bind that list to a gridview, I get  "System.ArgumentException: instance" at the first databinder : <%#DataBinder.Eval(Container.DataItem,"BasketName") %>

If I change my BasketHelper class to inherit from MarshalByRefObject or ContextBoundObject, then the databinding works as expected.

I guess there is some sort of issue with the context because the PolicyInjection is using the remoting proxy.

Can I use PolicyInjection with only interfaces or will I frequently need to inherit from these speccific classes?





Jul 3, 2008 at 3:05 PM
If I access the properties directly from the object, whether in code or in the aspx, the way you showed, then I can get the values.

The problem is that the main databinding scenarios with databinder do not work. ( DataBinder.GetPropertyValue, DataBinder.Eval and Bind)

While I can use MarshalByRefObject or ContextBoundObject for the current project, this issue will represent a significant barrier to our adoption of the PolicyInjection block.

Jul 4, 2008 at 5:07 PM
Hi Andrew,

I'm afraid there's an issue with remoting and the type descriptors when you have a transparent proxy for an interface; in that case instance.GetType().IsInstanceOf(instance) evaluates to false, causing the ArgumentException you eventually get. You could try registering custom type description providers for your intercepted objects, but I'm not sure that would work.

As I mentioned in a different thread, intercepting the request for GetType() to return the proxied type instead of the wrapped object's type solves this issue but could raise new ones. It's worth investigating, though.

Fernando



AndrewSeven wrote:
If I access the properties directly from the object, whether in code or in the aspx, the way you showed, then I can get the values.

The problem is that the main databinding scenarios with databinder do not work. ( DataBinder.GetPropertyValue, DataBinder.Eval and Bind)

While I can use MarshalByRefObject or ContextBoundObject for the current project, this issue will represent a significant barrier to our adoption of the PolicyInjection block.




Jul 4, 2008 at 11:47 PM

Thanks for your help,

I'll have a look at the RealProxy.

-Andrew

 

Sep 3, 2008 at 5:49 AM
I have this same issue.
The only way that i've got this to work is to retrieve the returned value from the PolicyInjection.Wrap method and then return a converted object to be used for data binding.

Anyone found a good solution for this?