我在我的 WebAPI 项目中使用 StructureMap MVC。
当我使用 xUnit 和 ReSharper 运行单元测试或集成测试时,我得到:
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.
这在我的测试中随机发生。当我尝试再次运行时,我没有收到此错误。
这是发生错误的地方:
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);
});
StackTrace 没有帮助:
at StructureMap.ObjectFactory.Initialize(Action`1 action) in c:\BuildAgent\work\767273992e840853\src\StructureMap\ObjectFactory.cs: line 61