Exception when using Ninject.Extensions.Factory with ILMerge

524 views
Skip to first unread message

Pete

unread,
Mar 30, 2012, 1:02:13 PM3/30/12
to nin...@googlegroups.com
Hi Remo,

When I use the Factory extension, I get this exception when the assemblies are merged using ILMerge. It's easy to repro but I can send you a sln demonstrating the problem if you like.

Any help appreciated.
Cheers,
Pete.

  <Target Name="AfterBuild">
    <ItemGroup>
      <ForMerging Include="@(ReferenceCopyLocalPaths)" Condition="%(Extension) == '.dll' OR %(Extension) == '.exe'" />
    </ItemGroup>
    <Exec Command="&quot;$(MSBuildProjectPath)..\build\tools\ilmerge.exe&quot; /ndebug /targetplatform:&quot;v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319&quot; /out:@(MainAssembly) &quot;@(IntermediateAssembly)&quot; @(ForMerging->'&quot;%(FullPath)&quot;', ' ')" />
    <Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
  </Target>
</Project>

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has
been thrown by the target of an invocation. ---> Ninject.ActivationException: Er
ror activating IInterceptor using conditional implicit self-binding of IIntercep
tor
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 Ninject.Activation.Context.Resolve()
   at Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding)
   at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
   at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Ob
ject target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAt
tributes, RuntimeType typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Obj
ect target, Object[] arguments, Signature sig, MethodAttributes methodAttributes
, RuntimeType typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke
Attr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisib
ilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke
Attr, Binder binder, Object[] parameters, CultureInfo culture)
   at Ninject.Infrastructure.Language.ExtensionsForIEnumerable.ToArraySlow(IEnum
erable series, Type elementType)
   at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent)
   at Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, I
Target target)
   at Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass4.<Create>b
__2(ITarget target)
   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)
   at Ninject.Activation.Context.Resolve()
   at Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at Ninject.ResolutionExtensions.Get[T](IResolutionRoot root, IParameter[] par
ameters)
   at NinjectIlmergeConflict.Program.Main(String[] args)

Remo Gloor

unread,
Mar 30, 2012, 5:16:34 PM3/30/12
to nin...@googlegroups.com

Hi Pete

 

It seems the StandardProvider is not able to create an instance of the FactoryInterceptor. What you can try is to use Reflection instead of dynamic method invocation by setting INinjectSetting.UseReflectionBasedInjection to true. Also be aware that the factory extension contains the FuncModule which is automatically loaded. Probably you have to load it manually after merging.

 

Regards Remo

--
You received this message because you are subscribed to the Google Groups "ninject" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ninject/-/5YAwFFobO18J.
To post to this group, send email to nin...@googlegroups.com.
To unsubscribe from this group, send email to ninject+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ninject?hl=en.

Pete

unread,
Mar 31, 2012, 12:38:19 PM3/31/12
to nin...@googlegroups.com
Remo,

Manually calling kernel.Load<FuncModule>() seems to fix the problem!

Many thanks again,
Pete.

Reply all
Reply to author
Forward
0 new messages