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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With