0

I'm a newbie on the subject, so I'll try to make this as clear as I can...

I created a WcfModule, where I load the following package:

Bind<IDistributorService>().To<DistributorService>().InRequestScope().Intercept().With<ExceptionInterceptor>();

At first, I don't receive any error, but I put an InterceptAttribute on my function:

[AttributeUsage(AttributeTargets.Method)]
public sealed class HandleExceptionsAttribute : InterceptAttribute
{
    public override IInterceptor CreateInterceptor(IProxyRequest request)
    {
        return request.Kernel.Get<ExceptionInterceptor>();
    }
}

[HandleExceptions]
public virtual Result<List<DistributorDataContract>> GetDistributor(string id)
{
   //...code...

I get an error in this function: (first line in method)

private ServiceHost CreateNewServiceHost(Type serviceType, Uri[] baseAddresses, WebHttpBehavior webBehavior, WebHttpBinding webHttpBinding)
{
  var host = base.CreateServiceHost(serviceType, baseAddresses);
  //...
}

With the error:

InvalidProxyConstructorArgumentsException was unhandled by user code Can not instantiate proxy of class: My.Namespace.DistributorService. Could not find a parameterless constructor.

Anyone who knows what the problem could be? Thanks!

RubenHerman
  • 1,674
  • 6
  • 23
  • 42

1 Answers1

0

This exception is thrown by castle core dynamic proxy when it is instructed to create a "class proxy" which does not have a parameterless (default) constructor and no constructor-arguments are passed to castle (see source).

My best guess is, that when you use ninject interception by attributes, ninject will instruct castle core to create a class-proxy, no matter whether your binding is Bind<IFoo>().To<Foo>() or Bind<Foo>().ToSelf().

It seems a bit strange, however, that ninject is not resolving and passing along all required constructor parameters.

What is the implementation of DistributorService and what's the implementation of the base class of the class containing CreateNewServiceHost?

Workaround: Of course, switching to the Intercept().With<TInterceptor>() syntax will probably also enable you to use interception (see http://codepyre.com/2010/03/using-ninject-extensions-interception-part-2-working-with-interceptors/)

BatteryBackupUnit
  • 12,934
  • 1
  • 42
  • 68