Note that there are some explanatory texts on larger screens.

plurals
  1. PONinject ToFactory works in Resharper unit tests, but not NCrunch
    text
    copied!<p>I'm using Ninject.Extensions.Factory with Ninject 3 to create a factory, which creates different types of <code>IFoo</code> based on the string provided to the factory. I've got a passing unit test, but oddly, only in the Resharper test runner. In the NCrunch test runner it fails. Is this a NCrunch config issue, or do I need to change the code?</p> <p>The interface:</p> <pre><code>public interface IFooFactory { IFoo CreateFoo(string name); } </code></pre> <p>The Ninject bindings:</p> <pre><code>kernel.Bind&lt;IFooFactory&gt;().ToFactory(() =&gt; new UseFirstParameterAsNameInstanceProvider()); kernel.Bind&lt;IFoo&gt;().To&lt;BarFoo&gt;().Named("Bar"); </code></pre> <p>The test:</p> <pre><code>[Test] public void CanCreateFooTest() { var factory = (IFooFactory) Kernel.GetService(typeof(IFooFactory)); var bar = factory.CreateFoo("Bar"); Assert.AreEqual(typeof(BarFoo), bar.GetType()); } </code></pre> <p>And the NCrunch exception:</p> <pre><code>System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation. ----&gt; Ninject.ActivationException : Error activating IInterceptor using conditional implicit self-binding of IInterceptor Provider returned null. Activation path: 2) Injection of dependency IInterceptor into parameter of constructor of type IFooFactoryProxy 1) Request for IFooFactory Suggestions: 1) Ensure that the provider handles creation requests properly. at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct&amp; sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) 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 Ninject.Infrastructure.Language.ExtensionsForIEnumerable.ToArraySlow(IEnumerable series, Type elementType) in c:\Projects\Ninject\ninject\src\Ninject\Infrastructure\Language\ExtensionsForIEnumerable.cs:line 29 at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent) in c:\Projects\Ninject\ninject\src\Ninject\Planning\Targets\Target.cs:line 149 at Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 114 at Ninject.Activation.Providers.StandardProvider.&lt;&gt;c__DisplayClass4.&lt;Create&gt;b__2(ITarget target) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 96 at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext() at System.Linq.Buffer`1..ctor(IEnumerable`1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at Ninject.Activation.Providers.StandardProvider.Create(IContext context) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 95 at Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\ninject\src\Ninject\Activation\Context.cs:line 157 at Ninject.KernelBase.&lt;&gt;c__DisplayClass10.&lt;Resolve&gt;b__c(IBinding binding) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 386 at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source) at Ninject.KernelBase.System.IServiceProvider.GetService(Type service) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 553 at FooProject.Tests.CanCreateFooTest() in C:\Projects\FooProject ... --ActivationException at Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\ninject\src\Ninject\Activation\Context.cs:line 165 at Ninject.KernelBase.&lt;&gt;c__DisplayClass10.&lt;Resolve&gt;b__c(IBinding binding) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 386 at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext() at System.Linq.Enumerable.&lt;CastIterator&gt;d__b1`1.MoveNext() at System.Linq.Buffer`1..ctor(IEnumerable`1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload