即使所有项目都引用 4.3.1,.NET 运行时也会尝试加载 FSharp.Core 4.3.0 [英] .NET runtime tries to load FSharp.Core 4.3.0 even if all projects reference 4.3.1

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

问题描述

我在 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.

当我的所有项目都引用 4.3.1 时,为什么它会搜索 FSharp.Core 4.3.0?如果我将所有项目引用从 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?

附言两个项目都针对 .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 的显式引用,这将不起作用,因为 FSharp.Data 2.2.0.0 是针对 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>

这应该可以解决问题.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆