IfSharp icon indicating copy to clipboard operation
IfSharp copied to clipboard

.NET Core + Type Providers

Open rudihorn opened this issue 5 years ago • 12 comments

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: image

The problem can slightly be improved by manually loading some further libraries: image

This still yields the error: image

Known workarounds

Not known yet.

Related information

  • Operating system: Ubuntu Server 18.10
  • Branch: Master + .NET Core autocompletion fix
  • .NET CoreCLR

rudihorn avatar Mar 20 '19 10:03 rudihorn

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.

rudihorn avatar Mar 20 '19 10:03 rudihorn

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!

cgravill avatar Mar 20 '19 12:03 cgravill

Yes and interestingly it is actually possible to execute code such as:

image

It is more the library implementation that is causing issues.

rudihorn avatar Mar 20 '19 13:03 rudihorn

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, FSharpOption1 legacyReferenceResolver) at FSharp.Compiler.Interactive.Shell.FsiEvaluationSession.Create(FsiEvaluationSessionHostConfig fsiConfig, String[] argv, TextReader inReader, TextWriter outWriter, TextWriter errorWriter, FSharpOption1 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](AsyncActivation1 ctxt, TResult result1, FSharpFunc2 part2) at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc2 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.

rudihorn avatar Mar 21 '19 12:03 rudihorn

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.

rudihorn avatar Mar 22 '19 10:03 rudihorn

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?

rudihorn avatar Mar 27 '19 09:03 rudihorn

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

cgravill avatar May 06 '19 20:05 cgravill

Btw I also made the Paket helper script work better in netcore, it might help getting the right dlls referenced too.

cgravill avatar May 06 '19 20:05 cgravill

I gave this a go with the latest and it seems to working for me now: image

The error highlighting looks to be a false positive: image

Based on this issue: https://github.com/dotnet/fsharp/issues/6688 it may not be anything specific to IF#

cgravill avatar May 19 '19 14:05 cgravill

@cgravill your sample code seems to work for me, except for the issue mention in #232

rudihorn avatar Jun 26 '19 10:06 rudihorn

I suppose a lot of this may be redundant with https://github.com/dotnet/fsharp/pull/5850.

rudihorn avatar Jun 26 '19 10:06 rudihorn

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.

cgravill avatar Jun 26 '19 11:06 cgravill