Autofixture和起订量V4Autofixture、起订量

2023-09-04 07:25:00 作者:ー颗心只容ー个人

我安装Autofixture和最小起订量使用Nuget.So我有订货数量版本4。

I installed Autofixture and Moq using Nuget.So I have moq version 4.

在运行下面的code

When running the following code

var fixture = new Fixture().Customize(new AutoMoqCustomization());
fixture.CreateAnonymous<ISomething>();

以下错误显示出来。

the following error shows up

System.IO.FileLoadException:可能   无法加载文件或程序集起订量,   版本= 3.1.416.3,文化=中立,   公钥= 69f491c39445e920

System.IO.FileLoadException : Could not load file or assembly 'Moq, Version=3.1.416.3, Culture=neutral, PublicKeyToken=69f491c39445e920'

我也试着重定向到V4的,但没有运气。

I've also tried redirected it to the v4,but with no luck.

<configuration>
  <runtime>
    <assemblyBinding>
    <dependentAssembly>
      <assemblyIdentity name="Moq" publicKeyToken="69f491c39445e920" culture="neutral"/>
      <bindingRedirect oldVersion="3.1.416.3" newVersion="4.0.10827.0"/>
    </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

这可能是什么问题就在这里?

What could be the problem here ?

推荐答案

为了装配在配置文件中绑定重定向,你需要指定瓮:架构 - 微软COM:ASM。 V1 命名空间中的&LT; assemblyBinding&GT;元素,就像这个例子:

In order to redirect an assembly binding in a configuration file, you need to specify the urn:schemas-microsoft-com:asm.v1 namespace in the <assemblyBinding> element, like in this example:

<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Moq"
                                  publicKeyToken="69f491c39445e920"
                                  culture="neutral"/>
                <bindingRedirect oldVersion="3.1.416.3"
                                 newVersion="4.0.10827.0"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

有趣的是指出,与.NET的早期版本编译的库组件(如起订量3 和 AutoFixture 2.1 )会自动在一个进程中运行的基于.NET 4.0,因为的在进程侧并行执行。下面是从MSDN报价关于这一点:

It's interesting to point out that library assemblies compiled with an earlier version of .NET (such as Moq 3 and AutoFixture 2.1) will automatically be loaded in a process running on .NET 4.0 because of In-Process Side-by-Side execution. Here's a quote from MSDN about this:

如果应用程序使用编译   .NET Framework 4的运行时间,但   包括建一个图书室   使用较早的运行时,该库   将使用.NET Framework 4运行时   为好。但是,如果你有一个   这是使用内置应用程序   早期运行和图书馆,这是   使用.NET Framework 4建成,你   必须强制你的应用程序也   使用.NET Framework 4

If an application is compiled using the .NET Framework 4 runtime but includes a library that was built using an earlier runtime, that library will use the .NET Framework 4 runtime as well. However, if you have an application that was built using an earlier runtime and a library that was built using the .NET Framework 4, you must force your application to also use the .NET Framework 4

相关资源:

重定向程序集版本