我在我的 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
最佳答案
您在使用 ReSharper 8 吗? xunit runner 有一个看起来像这样的讨厌的错误。确保将 xunit 扩展(ReSharper -> Extension Manager)更新为 1.2
关于c# - StructureMap 无法加载文件或程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18195379/