本文介绍了.NET运行时尝试加载FSharp.Core 4.3.0即使所有项目参考4.3.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个F#的一个项目,目标是F#3.1运行时(也就是FSharp.Core版本4.3.1)。然后,我创建了一个控制台C#应用程序,添加一个项目引用我的F#项目,增加了一个参考FSharp.Core.dll 4.3.1。

I've created a project in F# that targets F# 3.1 runtime (that is, FSharp.Core version 4.3.1). Then I've created a console C# application, added a project reference to my F# project, added a reference to FSharp.Core.dll 4.3.1.

编译没有任何错误或警告,但运行时会引发这个当我试图使用任何类型的F#项目:

Everything compiles without any errors or warnings, but the runtime throws this when I'm trying to use any type from F# project:

System.IO.FileLoadException : Could not load file or assembly 'FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

为什么它会搜索FSharp.Core 4.3.0当我所有的项目中引用4.3.1?如果我改变从4.3.1所有的项目引用4.3.0,一切都将正常工作,但什么是与4.3.1版本?

Why does it searches for FSharp.Core 4.3.0 when all my projects reference 4.3.1? If I change all project references from 4.3.1 to 4.3.0 that everything will work fine, but what's up with version 4.3.1?

P.S。这两个项目的目标.NET 4.5.1。我使用Microsoft Visual Studio 2013

P.S. Both project target .NET 4.5.1. I am using Microsoft Visual Studio 2013

推荐答案

这是野生的猜测,但基于异常你很可能是你有你的项目中的其他FSharp组件。

This is the wild guess but based on the exception you get it's likely that you have other FSharp assemblies inside your project.

因此​​,错误表明您正在使用的依赖关系之一,需要 FSharp.Core 4.3.0.0 。比方说,你的项目引用其他FSharp依赖例如像 FSharp.Data 2.2.0.0 。甚至,如果你已经添加在自己的项目中明确提到 FSharp.Core 4.3.1.0 这是不行的becasue FSharp.Data 2.2。 0.0 建对 FSharp.Core 4.3.0.0 。为了解决这个问题,你需要添加一个 bindingRedirect 到项目的配置文件的app.config

So the error indicates that one of the dependencies you're using requires FSharp.Core 4.3.0.0. Let's say your project references other FSharp dependencies like for example FSharp.Data 2.2.0.0. Even, if you have added an explicit reference in your own project to FSharp.Core 4.3.1.0 this won't work becasue FSharp.Data 2.2.0.0 was built against FSharp.Core 4.3.0.0. To fix that you need to add a bindingRedirect into your project configuration file app.config :

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

这应该可以解决这个问题。

This should fix the issue.

这篇关于.NET运行时尝试加载FSharp.Core 4.3.0即使所有项目参考4.3.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-15 03:17