Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Strange FileNotFoundException
DanHil
#1 Posted : Friday, April 26, 2013 1:23:07 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 11/12/2012(UTC)
Posts: 85

Thanks: 11 times
Was thanked: 3 time(s) in 3 post(s)
Hi Remco,

so, I got a new project where I can really do TDD and finally decided to buy NCrunch. It was just too much pain to perform TDD without it.

But now I got a rather strange issue.

I have the following setup:

Project under test:
WPF application .NET 3.5
References the Ninject NuGet package

Test project:
.NET 4
References the Ninject NuGet package

I can run the tests just fine in Resharpers runner.
But in NCrunch the test that really uses Ninject fails with:

Code:
*** Failures ***

Exception
System.IO.FileNotFoundException: System.IO.FileNotFoundException : Could not load file or assembly 'Ninject, Version=3.0.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7' or one of its dependencies. Das System kann die angegebene Datei nicht finden.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
   at Ninject.Modules.AssemblyNameRetriever.GetAssemblyNames(IEnumerable`1 filenames, Predicate`1 filter) in c:\Projects\Ninject\ninject\src\Ninject\Modules\AssemblyNameRetriever.cs:line 50#0
   at Ninject.Extensions.Conventions.BindingBuilder.AssemblyFinder.FindAssemblies(IEnumerable`1 assemblies, Predicate`1 filter) in c:\Projects\Ninject\ninject.extensions.conventions\src\Ninject.Extensions.Conventions\BindingBuilder\AssemblyFinder.cs:line 61#1
   at Ninject.Extensions.Conventions.BindingBuilder.ConventionSyntax.From(IEnumerable`1 assemblies) in c:\Projects\Ninject\ninject.extensions.conventions\src\Ninject.Extensions.Conventions\BindingBuilder\ConventionSyntax.From.cs:line 115#2
   at Ninject.Extensions.Conventions.BindingBuilder.ConventionSyntax.FromAssembliesMatching(String[] patterns) in c:\Projects\Ninject\ninject.extensions.conventions\src\Ninject.Extensions.Conventions\BindingBuilder\ConventionSyntax.From.cs:line 157#3
   at DeliveryConfirmation.TouchTerminal.CompositionRoot.<Execute>b__0(IFromSyntax x) in C:\Data\Projects\TouchTerminal\Application\DeliveryConfirmation.TouchTerminal\CompositionRoot.cs:line 26#4
   at Ninject.Extensions.Conventions.ExtensionsForIKernel.Bind(IBindingRoot kernel, Action`1 configure) in c:\Projects\Ninject\ninject.extensions.conventions\src\Ninject.Extensions.Conventions\Extensions\ExtensionsForIKernel.cs:line 59#5
   at DeliveryConfirmation.TouchTerminal.CompositionRoot.Execute() in C:\Data\Projects\TouchTerminal\Application\DeliveryConfirmation.TouchTerminal\CompositionRoot.cs:line 24#6
   at DeliveryConfirmation.TouchTerminal.CompositionRoot.Execute[T]() in C:\Data\Projects\TouchTerminal\Application\DeliveryConfirmation.TouchTerminal\CompositionRoot.cs:line 52#7
   at DeliveryConfirmation.TouchTerminal.Tests.CompositionRootTest.General.CompositionRootRegistersOneActiveCollectionConductor() in C:\Data\Projects\TouchTerminal\Application\DeliveryConfirmation.TouchTerminal.Tests\CompositionRootTest\General.cs:line 11#8


I checked the working directory of NCrunch (c:\Users\daniel.hilgarth\AppData\Local\NCrunch\).
The file Ninject.dll exists multiple times. Version is always 3.0.0.0, culture and public key token are also always the same as in the stack trace, but:
The runtime - as reported by ILSpy - is sometimes .NET 4.0 and sometimes .NET 2.0.
Because one of the projects is .NET 4 and one is .NET 3.5 this kinda makes sense, but it also seems to somehow confuse NCrunch.
However, this can't be the only reason, because I have the same scenario with Caliburn.Micro. It is also referenced in both projects.


Any ideas?

Remco
#2 Posted : Saturday, April 27, 2013 12:19:51 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Daniel -

Ninject is well known for its dynamic resolution of referenced assemblies, which can be a bit of a nightmare for a tool such as NCrunch. The first thing I would try in this situation is the Preload Assembly References configuration setting. Setting this to TRUE for all projects in your solution will allow NCrunch to enforce greater control over which referenced assemblies are loaded, which may have a chance at resolving this problem.

Most people that make use of Ninject also need to enable the Copy referenced assemblies to workspace configuration setting, as Ninject assumes that all referenced assemblies exist in the same output directory as the primary assembly.
DanHil
#3 Posted : Monday, April 29, 2013 8:59:07 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 11/12/2012(UTC)
Posts: 85

Thanks: 11 times
Was thanked: 3 time(s) in 3 post(s)
Hi Remco,

the first setting didn't change anything but setting "Copy referenced assemblies to workspace" to TRUE worked, thanks!

However, I wonder, what the actual problem was. If you study the stack trace closely you notice that the exception originated from within Ninject, meaning it already has to have been loaded.
Remco
#4 Posted : Monday, April 29, 2013 10:00:54 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
With my limited knowledge of Ninject, I can only guess that for some reason this framework wants to take responsibility for loading assemblies into the application domain manually. In a certain perspective of IoC, this would make sense, as the dependencies of an application may not be under the direct control of the application itself (and therefore need to be loaded dynamically), although I agree that when a framework can't find itself, something definitely doesn't look right!
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.036 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download