问题描述
我正在将一个相当小的 F# 项目从 Net Framework 迁移到 NET5.迁移非常简单,一切正常,包括测试.
但是,当我运行一些脚本时,我现在收到以下错误:
适用于 F# 5.0 的 Microsoft (R) F# Interactive 版本 11.0.0.0版权所有 (c) 微软公司.版权所有.如需帮助,请输入 #help;;>[正在加载 C:\Users\kkkma\AppData\Local\Temp\nuget\28772--091a5e4a-2a27-4d4d-9891-2b58055c5317\Project.fsproj.fsx正在加载 C:\GitHub\Berreman\Berreman\Analytics\Examples\References.fsx]命名空间 FSI_0002.Project命名空间 FSI_0002[正在加载 C:\Users\kkkma\AppData\Local\Temp\nuget\28772--091a5e4a-2a27-4d4d-9891-2b58055c5317\Project.fsproj.fsx]命名空间 FSI_0003.Project将会话绑定到C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.dll"...将会话绑定到C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.Numerics.dll"...System.TypeLoadException:无法从程序集System.Runtime,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"加载类型System.ICloneable".在 Berreman.MathNetNumericsMath.complexDiagonalMatrix(Int32 n, Complex e)在 C:\GitHub\Berreman\Berreman\Berreman\Geometry.fs:line 17 中的 Berreman.Geometry.complexIdentityMatrix(Int32 n)在 C:\GitHub\Berreman\Berreman\Berreman\Geometry.fs:line 307 中的 Berreman.Geometry.ComplexMatrix3x3.get_identity()在 C:\GitHub\Berreman\Berreman\Berreman\MaterialProperties.fs:line 70 中的 Berreman.MaterialProperties.Eps.fromRefractionIndex(RefractionIndex _arg1)在 FSI_0004.opticalProperties(RefractionIndex refractionIndex) 在 C:\GitHub\Berreman\Berreman\Analytics\Examples\Glass_01.fsx:line 51在 FSI_0004.getGlassInfo(Boolean useThickPlate, RefractionIndexThickness nh1, FSharpOption`1 nh2Opt, IncidentLightInfo light) 在 C:\GitHub\Berreman\Berreman\Analytics\Examples\Glass_01.fsx:line 61在 <StartupCode$FSI_0004>.$FSI_0004.main@() 在 C:\GitHub\Berreman\Berreman\Analytics\Examples\Glass_01.fsx:line 98由于错误而停止>当我从 C:\Users\kkkma\AppData\Local\Temp\nuget\28772--091a5e4a-2a27-4d4d-9891- 检查
(这是我运行脚本时 FSI 创建的文件夹)我看到它从 Project.fsproj.resolvedReferences.paths
时2b58055c5317C:\Users\kkkma\.nuget\packages\microsoft.netframework.referenceassemblies.net48\1.0 开始.0\build\.NETFramework\v4.8\Facades\System.Runtime.InteropServices.RuntimeInformation.dll
并且它还有一些其他的 Net Framework 解析引用.这让我相信 FSI 以某种方式决定"使用 Net Framework 而不是 NET 5.
文件 fsi.runtimeconfig.json
包含正确的信息:
{运行时选项":{tfm":net5.0",框架":{名称":Microsoft.NETCore.App",版本":5.0.0";}}}
有没有人知道如何强制 FSI 选择 NET 5 而不是 Net Framework?
截至 Visual Studio 2019 16.9 版,您可以启用使用 dotnet fsi
运行交互式 F# 脚本的选项.这适用于 .NET 5 代码.
这是通过工具设置的 >选项 >F# 工具 >F#互动 >使用 .NET Core 脚本.
完整的详细信息和说明可以在 https://devblogs.microsoft.com/dotnet/f-and-f-tools-update-for-visual-studio-16-9/
I am migrating a fairly small F# project from Net Framework to NET5. The migration was very easy and everything works including the tests.
However, when I run some scripts I am now getting the following error:
Microsoft (R) F# Interactive version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
For help type #help;;
>
[Loading C:\Users\kkkma\AppData\Local\Temp\nuget\28772--091a5e4a-2a27-4d4d-9891-2b58055c5317\Project.fsproj.fsx
Loading C:\GitHub\Berreman\Berreman\Analytics\Examples\References.fsx]
namespace FSI_0002.Project
namespace FSI_0002
[Loading C:\Users\kkkma\AppData\Local\Temp\nuget\28772--091a5e4a-2a27-4d4d-9891-2b58055c5317\Project.fsproj.fsx]
namespace FSI_0003.Project
Binding session to 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.dll'...
Binding session to 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.Numerics.dll'...
System.TypeLoadException: Could not load type 'System.ICloneable' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
at Berreman.MathNetNumericsMath.complexDiagonalMatrix(Int32 n, Complex e)
at Berreman.Geometry.complexIdentityMatrix(Int32 n) in C:\GitHub\Berreman\Berreman\Berreman\Geometry.fs:line 17
at Berreman.Geometry.ComplexMatrix3x3.get_identity() in C:\GitHub\Berreman\Berreman\Berreman\Geometry.fs:line 307
at Berreman.MaterialProperties.Eps.fromRefractionIndex(RefractionIndex _arg1) in C:\GitHub\Berreman\Berreman\Berreman\MaterialProperties.fs:line 70
at FSI_0004.opticalProperties(RefractionIndex refractionIndex) in C:\GitHub\Berreman\Berreman\Analytics\Examples\Glass_01.fsx:line 51
at FSI_0004.getGlassInfo(Boolean useThickPlate, RefractionIndexThickness nh1, FSharpOption`1 nh2Opt, IncidentLightInfo light) in C:\GitHub\Berreman\Berreman\Analytics\Examples\Glass_01.fsx:line 61
at <StartupCode$FSI_0004>.$FSI_0004.main@() in C:\GitHub\Berreman\Berreman\Analytics\Examples\Glass_01.fsx:line 98
Stopped due to error
>
When I examine Project.fsproj.resolvedReferences.paths
from C:\Users\kkkma\AppData\Local\Temp\nuget\28772--091a5e4a-2a27-4d4d-9891-2b58055c5317
(and that's the folder created by FSI when I run the script) I see that it starts from C:\Users\kkkma\.nuget\packages\microsoft.netframework.referenceassemblies.net48\1.0.0\build\.NETFramework\v4.8\Facades\System.Runtime.InteropServices.RuntimeInformation.dll
and it also has some other Net Framework resolved references. Which makes me believe that FSI somehow "decides" to use Net Framework instead of NET 5.
The file fsi.runtimeconfig.json
contains correct information:
{
"runtimeOptions": {
"tfm": "net5.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "5.0.0"
}
}
}
Does anyone have an idea how to force FSI pick up NET 5 instead of Net Framework?
As of Visual Studio 2019 version 16.9, you can enable an option to use dotnet fsi
to run interactive F# scripts. This works with .NET 5 code.
This is set via Tools > Options > F# Tools > F# Interactive > Use .NET Core Scripting.
Full details and instructions can be found at https://devblogs.microsoft.com/dotnet/f-and-f-tools-update-for-visual-studio-16-9/
这篇关于如何使 FSI 在 NET5 下工作并生成愚蠢的 stackoverflow 消息“标题不能包含..."闭嘴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!