PIAB will raise exception - "Object does not match target type."

Topics: Policy Injection Application Block
Mar 25, 2008 at 3:23 AM
Hi All:
When I used policyInejctionBehavior, sometimes i would encounter the error "Object does not match target type". And I found the error was thrown at InterceptingRealProxy.cs(line 136)->object returnValue = callMessage.MethodBase.Invoke(target, invocation.Arguments);

And callMessage.MethodBase.DeclaringType is Interface, but target is its instace.

In other words, my code structure is:
ServiceContract(Namespace = "http://xxx", Name = "xxx")
public interface IA

class B: IA
{
...
}

Then, the "target" is class B's instance, but "callMessage.MethodBase.DeclaringType" is the interface IA. So the "target" should be the instance of the interface.

Why did it tell me "Object does not match target "? Could anybody tell me the reason and how could i solve it? Thanks

The error's stacktrace is:
at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Microsoft.Practices.EnterpriseLibrary.PolicyInjection.RemotingInterception.InterceptingRealProxy.<>c_DisplayClass1.<Invoke>b_0(IMethodInvocation input, GetNextHandlerDelegate getNext)
at Microsoft.Practices.EnterpriseLibrary.PolicyInjection.HandlerPipeline.Invoke(IMethodInvocation input, InvokeHandlerDelegate target)
at Microsoft.Practices.EnterpriseLibrary.PolicyInjection.RemotingInterception.InterceptingRealProxy.Invoke(IMessage msg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at NCS.IConnect.Security.IMembership.ValidateUser(String username, String password, String applicationName)
at SyncInvokeValidateUser(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
May 19, 2008 at 4:20 PM
Hi,

Tom Hollander posted a work around for this situation.

Fernando