好吧所以我花了一天时间尝试使用Autofac,Moq和Moq.Contrib解决这个问题。我一直在使用Nuget将我的各种项目升级到最新版本的东西,包括Autofac。
我的项目涉及以下内容: -
<Reference Include="Autofac, Version=3.5.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Autofac.3.5.2\lib\net40\Autofac.dll</HintPath>
</Reference>
<Reference Include="Autofac.Integration.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Autofac.Mvc5.3.3.3\lib\net45\Autofac.Integration.Mvc.dll</HintPath>
</Reference>
<Reference Include="AutofacContrib.CommonServiceLocator, Version=2.6.3.862, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Autofac.CommonServiceLocator.Indy.2.6.3.863\lib\net40\AutofacContrib.CommonServiceLocator.dll</HintPath>
</Reference>
我遵循了这个问题Weird exception after updated Autofac
中给出的建议然而,当我运行单元测试时,我得到如下错误。
SetUp : System.MissingMethodException : Method not found: 'Autofac.Builder.IRegistrationBuilder`3<!0,!1,!2> Autofac.Builder.IRegistrationBuilder`3.PropertiesAutowired(Autofac.PropertyWiringFlags)'. at Moq.Contrib.Indy.AutoMockContainer.<Create>b__0<T>(ContainerBuilder builder) at Moq.Contrib.Indy.AutoMockContainer.Update(Action`1 registration) at Moq.Contrib.Indy.AutoMockContainer.ResolveOrCreate(Action`1 registration) at Moq.Contrib.Indy.AutoMockContainer.Create() at NUnitTests.TestContext`1..ctor() in TestContext.cs: line 24 at NUnitTests.AccountsAccountLutTests..ctor()
我已经从App.config,packages.config和.csproj文件中完全删除了对Autofac和Moq的所有引用,然后我使用NuGet重新添加了所需的引用,以便正确完成依赖项。然而,似乎无论我做什么,我都会在尝试运行我的测试时出现运行时错误...它似乎和感觉好像最新的Autofac被打破了?感谢任何建议,我很乐意让我的测试再次运作。
或者这些东西不再兼容了,我应该放弃并朝着不同的方向前进?
关心朱利安
答案 0 :(得分:1)
包Moq.Contrib.Indy引用Autofac.CommonServiceLocator.Indy,后者又指定它引用Autofac 2.6.3.862。
Autofac 2.6.3已经很老了。 2012年6月老。从那以后,Autofac发生了很多变化。这些&#34; Indy&#34;您引用的套餐无法确保它们与新的Autofac正确向前兼容,这就是您看到此问题的原因。
我在猜测&#34; Indy&#34;软件包需要实际指定不仅它们需要Autofac&gt; = 2.6.3,而还它们需要Autofac&lt; 3.0.0。
我建议您在短期内恢复使用的旧版Autofac。从长远来看,我建议您与the author of those Indy packages联系,看看是否可以更新它们以与最新的Autofac兼容。