IfSharp
IfSharp copied to clipboard
.NET Core + Type Providers
Description
There is some issue loading the correct libraries to use Type Providers on .NET Core. While this is directly relevant to Type Providers, the issue itself is broader and should be solved.
Repro steps
Run the following code:
The problem can slightly be improved by manually loading some further libraries:
This still yields the error:
Known workarounds
Not known yet.
Related information
- Operating system: Ubuntu Server 18.10
- Branch: Master + .NET Core autocompletion fix
- .NET CoreCLR
The complaint about netstandard.dll
is a bit more worrying, as it refuses to load the netstandard library when you try to force load it. I'm assuming this is an issue with the setup of the environment.
Does the type provider work correctly in an F# Interactive session outside of IFSharp? My understanding is that each of the parts is only recently working on .NET Core.
Getting this working also would be great!
Yes and interestingly it is actually possible to execute code such as:
It is more the library implementation that is causing issues.
The main difference I can see between fsi.exe
and IfSharp is that fsi.exe
calls FsiEvaluationSession.GetDefaultConfiguration
with useAuxLib=true
, while IfSharp sets it to false. Setting it to true in IfSharp causes an exception to be thrown:
Unhandled Exception: System.TypeInitializationException: The type initializer for '<StartupCode$IfSharp-Kernel>.$Evaluation' threw an exception. ---> System.Exception: Error creating evaluation session: StopProcessingExn None at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1647.Invoke(String message) at FSharp.Compiler.Interactive.Shell.FsiEvaluationSession..ctor(FsiEvaluationSessionHostConfig fsi, String[] argv, TextReader inReader, TextWriter outWriter, TextWriter errorWriter, Boolean fsiCollectible, FSharpOption
1 legacyReferenceResolver) at FSharp.Compiler.Interactive.Shell.FsiEvaluationSession.Create(FsiEvaluationSessionHostConfig fsiConfig, String[] argv, TextReader inReader, TextWriter outWriter, TextWriter errorWriter, FSharpOption
1 collectible, FSharpOption1 legacyReferenceResolver) at IfSharp.Kernel.Evaluation.startSession() in /home/administrator/IfSharp/src/IfSharp.Kernel/Evaluation.fs:line 61 at <StartupCode$IfSharp-Kernel>.$Evaluation..cctor() in /home/administrator/IfSharp/src/IfSharp.Kernel/Evaluation.fs:line 80 --- End of inner exception stack trace --- at IfSharp.Kernel.Evaluation.get_fsiEval() at IfSharp.Kernel.IfSharpKernel.doShell() in /home/administrator/IfSharp/src/IfSharp.Kernel/Kernel.fs:line 626 at <StartupCode$IfSharp-Kernel>[email protected](Unit unitVar) in /home/administrator/IfSharp/src/IfSharp.Kernel/Kernel.fs:line 727 at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation
1 ctxt, TResult result1, FSharpFunc2 part2) at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc
2 firstAction) --- End of stack trace from previous location where exception was thrown --- at [email protected](ExceptionDispatchInfo edi) at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) at <StartupCode$FSharp-Core>[email protected](Object o) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location where exception was thrown --- at System.Threading.ThreadPoolWorkQueue.Dispatch()
I'm guessing this is thrown in fsi.fs
at line 2533 onwards:
let (tcGlobals,frameworkTcImports,nonFrameworkResolutions,unresolvedReferences) =
try
let tcConfig = tcConfigP.Get(ctokStartup)
checker.FrameworkImportsCache.Get (ctokStartup, tcConfig) |> Cancellable.runWithoutCancellation
with e ->
stopProcessingRecovery e range0; failwithf "Error creating evaluation session: %A" e
let tcImports =
try
TcImports.BuildNonFrameworkTcImports(ctokStartup, tcConfigP, tcGlobals, frameworkTcImports, nonFrameworkResolutions, unresolvedReferences) |> Cancellable.runWithoutCancellation
with e ->
stopProcessingRecovery e range0; failwithf "Error creating evaluation session: %A" e
Not entirely sure what the useAuxLib
property does internally though.
Does the type provider work correctly in an F# Interactive session outside of IFSharp? My understanding is that each of the parts is only recently working on .NET Core.
Turns out this might have been key. I added a forced reference to Microsoft.NETCore.App
version 2.2.3, and it seems to now be "somewhat working". Previously it would automatically set the a reference to that library to version 2.2.0 in IfSharpNetCore.runtimeconfig.json, but with the additional reference it explicitly has a dependency of 2.2.3 and works.
It still requires the manual loading of some additional libraries, and Intellisense is still complaining about missing "netstandard.dll", but the functionality works :) I'll submit a PR soon.
Edit: Ignore this comment it, the error was only the intellisense / typechecking and not an issue with the execution. The highlighting issue is not solved.
Should libraries which are normally loaded during common projects such as "System.Runtime.Extensions.dll" be loaded by default though? Especially if they are needed by something like Type providers?
I've add the automatic referencing of netstandard in #218 so the highlighting issue should be solved. I'm not sure the right answer about automatically referencing other libraries, it's convenient but may turn out problematic and a breaking change if we have to withdraw it later...
Btw I also made the Paket helper script work better in netcore, it might help getting the right dlls referenced too.
I gave this a go with the latest and it seems to working for me now:
The error highlighting looks to be a false positive:
Based on this issue: https://github.com/dotnet/fsharp/issues/6688 it may not be anything specific to IF#
@cgravill your sample code seems to work for me, except for the issue mention in #232
I suppose a lot of this may be redundant with https://github.com/dotnet/fsharp/pull/5850.
Yes, I'm very hopeful about that change to #r. We could also potentially just use FAKE's current syntax which implements an approximation to it: https://github.com/fsprojects/IfSharp/issues/112#issuecomment-504662581 which now supports unmanaged references too.