Question

I'm using StructureMap MVC on my WebAPI project.
When I run the unit tests or integration tests, with xUnit and ReSharper I'm getting:

System.IO.FileNotFoundException
Could not load file or assembly 'MyApi.MyServices, Version=1.0.0.0, Culture=neutral,     PublicKeyToken=null' or one of its dependencies. The system cannot find the path specified.

This occurs randomly on my tests. When I try to run again I don't get this error.

Here is where the error occurs:

ObjectFactory.Initialize(x =>
{
    x.For<IProvider>().LifecycleIs(Lifecycles.GetLifecycle(InstanceScope.PerRequest)).Use<SQLiteProvider>();
    x.For<ILog>().LifecycleIs(Lifecycles.GetLifecycle(InstanceScope.Singleton)).Use(Logger.Object);
    x.For<ISession>().LifecycleIs(Lifecycles.GetLifecycle(InstanceScope.PerRequest)).Use(() => Session);
});

The StackTrace isn't helpful:

 at StructureMap.ObjectFactory.Initialize(Action`1 action) in c:\BuildAgent\work\767273992e840853\src\StructureMap\ObjectFactory.cs: line 61
Was it helpful?

Solution

Are you using ReSharper 8? The xunit runner had a nasty bug that looks like this. Make sure you update the xunit extension (ReSharper -> Extension Manager) to 1.2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top