System.Xml.Linq依赖于未签名的System.Core

时间:2017-05-15 06:18:41

标签: f# .net-framework-version f#-fake

在面向.NET Framework 4.6.2的F#可执行文件中,加载,修改XML文件,然后通过System.Xml.Linq将其保存回磁盘:

let doc = XDocument.Load apiDoc
...file is modified....
doc.Save apiDoc

将项目从Visual Studio 2015移动到Forge / FAKE / IonIDE并执行:

  • windows-sdk-10.0 10.0.26624
  • visualfsharptools 4.0
  • microsoft-build-tools 15.0.26228.0
  • visualstudiocode 1.11.2

遇到以下错误:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or 
assembly 'System.Core, Version=3.5.0.0, Culture=neutral, 
PublicKeyToken=null' or one of its dependencies. The system cannot find the 
file specified.
   at System.Xml.Linq.XText.WriteTo(XmlWriter writer)
   at System.Xml.Linq.XElement.WriteTo(XmlWriter writer)
   at System.Xml.Linq.XElement.WriteTo(XmlWriter writer)
   at System.Xml.Linq.XElement.WriteTo(XmlWriter writer)
   at System.Xml.Linq.XDocument.WriteTo(XmlWriter writer)
   at System.Xml.Linq.XDocument.Save(XmlWriter writer)
   at System.Xml.Linq.XDocument.Save(String fileName, SaveOptions options)
   at System.Xml.Linq.XDocument.Save(String fileName)
   at Migrate.main(String[] argv) in c:\Projects\Migration\src\app\Migration\Migrate.fs:line 133

我在加载文档之前尝试添加以下内容,但发生了同样的错误:

Assembly.Load("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") |> ignore

注意:

  • 在Windows 10开发计算机上安装了Framework 3.5和4.5.2到4.7版本。
  • 安装了Framework版本3.5和4.5.2到4.6.2的Windows 2012 R2服务器上会出现相同的行为。
  • FSharp.Core.dll随可执行文件一起发布。

这让我感到困惑,因为4.6.2没有3.5依赖关系,并且错误中给出的预期引用没有强名称。

2 个答案:

答案 0 :(得分:0)

这是我学习VSCode / Ionide的一个例子。首次设置项目时,System.Xml.Linq无法解析。我错误地将它添加到没有版本约束的paket.references文件中。这促使Paket下拉Mono package。作为3.5版本的软件包,它对System.Core版本3.5具有隐式依赖性。

从项目中删除软件包,然后在Ionide中使用预期的F#:Add Reference命令后,项目中添加了正确的4.6.2框架参考。

答案 1 :(得分:0)

对于使用FSharp脚本的用户,您可以引用该程序集,然后打开System.Xml.Linq

#r "System.Xml.Linq.dll"
open System.Xml.Linq