dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.87k stars 780 forks source link

since release of FCS 34.0.1: FSharp.Core.dll was not found or is invalid #9064

Closed goswinr closed 3 years ago

goswinr commented 4 years ago

Since release of FSharp.Compiler.Service 34.0.1 (and higher versions too) I get this error

error FS0084: Assembly reference 'FSharp.Core.dll' was not found or is invalid

when calling FsiEvaluationSession.Create(...) hosted in a Rhino3d Plugin

Is version 33.0.1 using another version of FSharp.Core than 34.0.1 ? May it be possible to fix this by telling the Rhino.PlugIn how to explicitly reference FSharp.Core ? With binding redirects? cc @sbaer @jesterking

Here is a minimal repro to reproduce this : https://github.com/goswinr/FsiRhinoTest

I previously reported this on FCS https://github.com/fsharp/FSharp.Compiler.Service/issues/935

sbaer commented 4 years ago

You could try forcing FSharp.Core.dll to load by using Assembly.LoadFrom in the plug-in's OnLoadPlugIn override.

cartermp commented 4 years ago

@goswinr Try removing this: <PackageReference Update="FSharp.Core" Version="4.7.0" />

Explicit FSharp.Core references are only useful for library authors looking to pin their lowest-compatible FSharp.Core for consumers.

goswinr commented 4 years ago

Is there a way to have more diagnostic error messages? @cartermp , unfortunately removing the FSharp.Core package reference did not help. how is dotnet build deciding which version of FSharp.Core to put in the output folder now? @sbaer Explicitly loading it does not make a change either.

I included these suggestions in the test repro.

dsyme commented 4 years ago

@goswinr Did you make progress on this? I can look at your repro if you like

goswinr commented 4 years ago

@dsyme Yes, it would be great if you could look at the test repro. Follow the steps in the readme. I just tried with the latest 37.0.0 nuget. same message:

Microsoft (R) F# Interactive version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> 

error FS0084: Assembly reference 'FSharp.Core.dll' was not found or is invalid

Would it be possible to have a better error message? Detailing why it is invalid ?

I saw some binding errors in the fusion log . ( using this tool https://github.com/awaescher/Fusion) image

but I am not sure they are relevant. version 33.0.1 also shows similar errors.

goswinr commented 3 years ago

With FCS 40.0 I still get the same StopProcessingExn exception inFSharp.Compiler.Interactive.Shell.FsiEvaluationSession..ctor(..) in addition, the FSI error stream says:

error FS0078: Unable to find the file 'FSharp.Core.dll' in any of
 C:\Windows\Microsoft.NET\Framework64\v4.0.30319
 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\WPF
 C:\Program Files\Rhino 7\System
 C:\Program Files\Rhino 7\System\

however, I can't put Fsharp.Core in any of those directories because of insufficient user rights. Is there any way to make the FsiEvaluationSession constructor load FSharp.Core.dll from the same location as FSharp.Compiler.Service.dll ?

@KevinRansom there is also no app.config that i could modify as suggested here https://github.com/dotnet/fsharp/issues/10467#issuecomment-774639796

goswinr commented 3 years ago

After more than a year, I finally managed to fix this. 🎉 The constructor of FsiEvaluationSession queries the current directory. However, when FCS is hosted in another app, this directory probably does not contain FSharp.Core.dll in my case it is C:\Program Files\Rhino 7\System\ So to fix this, I had to set the current directory to the location of FSharp.Core.dll befor calling FsiEvaluationSession.Create(...) . I added: Directory.SetCurrentDirectory(Path.GetDirectoryName(Reflection.Assembly.GetAssembly([].GetType()).Location)) Now it works !

JustinGrote commented 10 months ago

Just a bump that I was bit by this while hosting the FCS compiler in .NET 8. @goswinr's workaround worked for me (thank you for your suffering)