Wierd PIAB bug

Jul 3, 2009 at 1:54 PM

Hi we are using PIAB for security interception on our business objects. The current configuration uses a custom matching rule that matches all interface methods that derive for our base business logic interface and it worked perfectly until for some weird reason interception got called on Dispose method that is not a part of any of business interfaces that our rule matches. IDisposable is defined on our objects but the object needs to be cast to IDisposable before you can call dispose.

 

I checked the handler’s pipeline and it contained 6 instead of 5 (no. of methods in the interface) handler pipelines and the metadata key used to match for one was the same as the dispose method one. So interception is working as it should the weird thing is that the handler pipeline with dispose methods metadata key shouldn’t even be there and that this extra handler is not deterministic - it always at the same spot on a particular computer, but no 2 computers have the problem with the same business object and one computer even has handlers attached to GetType method that is not a part of any interface.

 

We also checked if all interfaces in our classes get handled but that’s not the case since most of our business classes implement at least 5-6 interfaces and only methods from our interface that derives from the for mentioned base interface get handled plus one extra method that causes problems.

Anyone else had this problem?

Jul 6, 2009 at 9:38 AM

Hi,

I never hit this kind of behaviour before. Do you have a quick repro steps for this one? If you have a simple application that replicates the said behaviour please send us a copy.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Jul 6, 2009 at 10:50 AM

At the moment the bug is appearing only in one solution others are not affected. Im tring to reporduce the bug on a smaler project but we cant find any common issue with the business logic objects. So if i manage to reproduce it on a smaller solution I can post it here but don't know it that will help since if i take the source and copy it to another computer build it there bug usually disaperars or moves to some other intercepted class.

As far as we figured out it stays put if you build your assemblies and deploy the bug stays put.

More info on how curretn matching works:

[ServiceContract(Name="IBusinessObject")]
public interface IBusinessLogicObject
{
    // Methods
    [OperationContract(Name="IsAlive")]
    bool IsAlive();
    [OperationContract(Name="LooksAlive")]
    bool LooksAlive();
}

[ServiceContract(Name="IActuality")]
public interface IActuality : IBusinessLogicObject
{
    // Methods
    [OperationContract(Name="ActivateActuality")]
    bool ActivateActuality(Guid actualityId, bool activate, Session session);
    [OperationContract(Name="DeleteActuality")]
    bool DeleteActuality(Guid actualityId, Session session);
    [OperationContract(Name="GetActualityDetails")]
    DSActuality GetActualityDetails(Guid actualityId, Session session);
    [OperationContract(Name="GetActualityList")]
    DSActualityList GetActualityList(Guid languageId, bool activeOnly, Session session);
    bool UpdateActuality(Guid actualityId, Guid languageId, string name, string description, Guid promotionItemId, bool updateContent, byte[] content, string mimeType, byte preferredSlot, DateTime validFrom, DateTime validTo, bool active, Session session);
}

Mattching Rule (the only rule we use):

public bool Matches(MethodBase member)
{
        return (member.DeclaringType.IsInterface && typeof(IBusinessLogicObject).IsAssignableFrom(member.DeclaringType));
}

I have no idea how Dispose form IDisposable gets matched to this rule. I did see that we have a extension method that handles Dispose calls depending on object location (remote, locla) that is defined as an extension method to IBusinessObject.

public static void Dispose(this IBusinessLogicObject value)
{
          //Some stuff
}


 

Jul 7, 2009 at 7:16 AM
Edited Jul 7, 2009 at 7:17 AM

Well if you managed to, please post the repro steps.  Couldn't you at least define the exact class inheritance/structure? 

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jul 7, 2009 at 8:32 AM
Edited Jul 7, 2009 at 10:01 AM

IBusinessLogicObject is implemented in BusinessLogicObject base class that also defines IDisposable as a seperate inteface.. Actuality business object derives from BusinessLogicObject and implements IActuality inteface. Dispose logic for Actuality is added by overriding Dispose(bool) protected method in IDisposable implementation.

My previous contains interface definitions and inheritance.

Class definitions and inheritance:

public class BusinessLogicObject : IBusinessLogicObject, IDisposable { ... }

public class Actuality: BusinessLogicObject, IActuality{ ... }

Our UI objects access BusinessLogicObject by using a special Client object that creates the business logic instances using Activator.CreateInstance(Type) then calls Wrap<T>(T) (using IActivity as dynamic type parameter) on the created instance and returns the proxied object.

Jul 7, 2009 at 9:35 AM

I don't see how will this get intercepted, please verify this code, this is how I created the class:

IActivity activity = Activator.CreateInstance(typeof(Activity)) as Activity;
activity = PolicyInjection.Wrap<IActivity>(activity);
((IDisposable)activity).Dispose() ;

 

In your custom matching rule, you only say that it match if it is of type IBusinessLogicObject.  Using the code above, the Match method always returns false.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jul 7, 2009 at 9:58 AM

I do get matches since IActivity derives from IBusinessObject so typeof(IBusinessObject).IsAssignableFrom(method.DeclaringType) returns true when metdhod.DeclaringType is typeof(IActivity).

Chacked it in code right now and for all IACtivty member methods Match evaluates to true.

Jul 7, 2009 at 10:00 AM
Edited Jul 7, 2009 at 10:37 AM

Ups.. sorry for the typos atm i was writing some Activity module and made a typing mistake i repaired my previous post describing inheritance. IActivity should be IActuality and Activity should be Actuality.

Jul 7, 2009 at 10:14 AM

Ok, I missed the IActuality : IBusinessObject.  I'll continue with my investigation.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jul 17, 2009 at 11:35 AM

Well I decided to do a workarround for this and added a matching rule recheck to all call handlers, since this was just to random to reproduce and typically fixes itself after a while. Just couldn't reporduce it on a small sacale but larger scale projects tended to have at least 2-4 diffrent methods that got proxied that were not supposed to be proxied.

Jul 17, 2009 at 11:45 AM

Sorry for not getting back,  I had this thought that I already replied to you.  Well, I couldn't really reproduce your case.  If you will have an update, let us know.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com