Reputation: 41
I have a WCF Service that I am using constructor injection with Ninject.
This is on the .net 4.5 framework
When I access the service I get the following error.
[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
System.Activator.CreateInstance(Type type) +66
System.ServiceModel.Configuration.ServiceAuthorizationElement.CreateBehavior() +504
System.ServiceModel.Description.ConfigLoader.LoadBehaviors(ServiceModelExtensionCollectionElement`1 behaviorElement, KeyedByTypeCollection`1 behaviors, Boolean commonBehaviors) +188
System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress, Boolean skipHost) +12973997
System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, ServiceElement serviceSection) +69
System.ServiceModel.ServiceHostBase.ApplyConfiguration() +178
System.ServiceModel.ServiceHost.ApplyConfiguration() +61
System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses) +184
System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses) +46
Ninject.Extensions.Wcf.NinjectAbstractServiceHost`1..ctor(IServiceBehavior serviceBehavior, T instance, Uri[] baseAddresses) +208
Ninject.Extensions.Wcf.NinjectIISHostingServiceHost`1..ctor(IServiceBehavior serviceBehavior, T instance, Uri[] baseAddresses) +43
DynamicInjectoredd01103a277420e8359d2f089e3fee2(Object[] ) +199
Ninject.Activation.Providers.StandardProvider.Create(IContext context) +884
Ninject.Activation.Context.ResolveInternal(Object scope) +217
Ninject.Activation.Context.Resolve() +276
Ninject.<>c__DisplayClass15.<Resolve>b__f(IBinding binding) +86
System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +157
System.Linq.Enumerable.Single(IEnumerable`1 source) +121
Ninject.ResolutionExtensions.Get(IResolutionRoot root, Type service, IParameter[] parameters) +69
Ninject.Extensions.Wcf.BaseNinjectServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) +212
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +492
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +1429
System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +52
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +598
[ServiceActivationException: The service '/Authentication.svc' cannot be activated due to an exception during compilation. The exception message is: No parameterless constructor defined for this object..]
System.Runtime.AsyncResult.End(IAsyncResult result) +486568
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +174
System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar) +374230
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +9708641
Now the odd part to me is this. I set a break point in constructor, when I call the service the constructor with injection is called and properly injects everything and then returns. This error occurs after the return from the non-default constructor.
This is my constructor
private IAuthenticationBl Bl;
public Authentication(IAuthenticationBl AuthenticationBl)
{
Bl = AuthenticationBl;
}
I have included in the service markup
Factory="Ninject.Extensions.Wcf.NinjectServiceHostFactory"
Any help is appreciated.
Upvotes: 2
Views: 613
Reputation: 41
For anyone running into a similar issue. The root of the problem was the service had a CustomAuthorizationPolicy that required an injection. This required creating a CustomServiceHostFactory.
Upvotes: 2