Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DependencyManager Win32Exception on non windows #3992

Open
vilinski opened this issue Feb 26, 2021 · 9 comments
Open

DependencyManager Win32Exception on non windows #3992

vilinski opened this issue Feb 26, 2021 · 9 comments

Comments

@vilinski
Copy link

vilinski commented Feb 26, 2021

Description

Didn't found how to add private nuget sources in F# scripts. So tried to install paket as a package manager.
Followed instructions at https://fsprojects.github.io/Paket/fsi-integration.html
But this throws Win32Exception on Macos

Repro steps

  1. downloaded the FSharp.DependencyManager.Paket nuget sending the line to F# interactive
#r "nuget: FSharp.DependencyManager.Paket"
  1. Copy the manager dll to the folder where current sdk is installed
cp ~/.nuget/packages/fsharp.dependencymanager.paket/6.0.0-beta8/lib/netstandard2.0/FSharp.DependencyManager.Paket.dll \
    /usr/local/share/dotnet/sdk/5.0.103/FSharp/
  1. Created a script, referencing a package using paket
#r "paket: nuget FParsec"

open FParsec
  1. runned the script
$ dotnet fsi paketdeps.fsx

Expected behavior

Expected it would add a package to the script

Actual behavior

❯ dotnet fsi paketdeps.fsx
:paket> using /Users/username/.nuget/packages/paket/5.257.0/tools/paket.exe
exception while resolving dependencies: System.ComponentModel.Win32Exception (8): Exec format error
   at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at ReferenceLoading.PaketHandler.ResolveDependenciesForLanguage$cont@176(String targetFramework, String scriptDir, IEnumerable`1 prioritizedSearchPaths, String fileType, String workingDir, FileInfo workingDirSpecFile, String rootDir, FSharpList`1 packageManagerTextLines, String loadScript, Unit unitVar)
   at ReferenceLoading.PaketHandler.ResolveDependenciesForLanguage(String fileType, String targetFramework, IEnumerable`1 prioritizedSearchPaths, String scriptDir, String scriptName, IEnumerable`1 packageManagerTextLinesFromScript)
   at ReferenceLoading.PaketHandler.ResolveDependencies(String targetFramework, String scriptDir, String scriptName, IEnumerable`1 packageManagerTextLinesFromScript)
   at Microsoft.FSharp.DependencyManager.Paket.PaketDependencyManagerProvider.ResolveDependencies(String scriptDir, String mainScriptName, String scriptName, IEnumerable`1 packageManagerTextLines, String targetFramework)


/Users/username/Projects/fsharp/paketdeps.fsx(3,6): error FS0039: The namespace or module 'FParsec' is not defined.

Known workarounds

use nuget instead of paket as a package manager

#r "nuget: FParsec"

open FParsec

Additional info

  • macos catalina,
  • .net sdk. 5.0.103
  • paket cli tool - tried both latest stable 5.257.0 and latest prerelease 6.0.0-beta8
    in both cases is shown the usage of 5.257.0 version
@iwinux
Copy link
Contributor

iwinux commented Apr 10, 2021

Same error here on macOS 10.15.7 + .NET SDK 5.0.201.

@smoothdeveloper
Copy link
Contributor

@vilinsky thanks for reporting the issue.

downloaded the FSharp.DependencyManager.Paket nuget sending the line to F# interactive
fsharp #r "nuget: FSharp.DependencyManager.Paket"

Maybe you can contribute to the discussion from this point: dotnet/fsharp#8880 (comment)

from my perspective, just this line should be enough for FSI to pickup the paket extension, if you share that idea, please engage there.

For the error starting the process, as I've not used the extension outside windows, maybe there is some extra work to run paket.exe needed in how the process is started:

let startInfo =
System.Diagnostics.ProcessStartInfo(
FileName = toolPath,
WorkingDirectory = workingDir,
RedirectStandardOutput = true,
RedirectStandardError = true,
Arguments = MakeDependencyManagerCommand fileType targetFramework rootDir,
CreateNoWindow = true,
UseShellExecute = false)
use p = new System.Diagnostics.Process()
let errors = ResizeArray<_>()
let log = ResizeArray<_>()
p.StartInfo <- startInfo
p.ErrorDataReceived.Add(fun d -> if not (isNull d.Data) then errors.Add d.Data)
p.OutputDataReceived.Add(fun d ->
if not (isNull d.Data) then
Console.ForegroundColor <- ConsoleColor.Green
Console.Write ":paket>"
Console.ResetColor()
Console.WriteLine (" " + d.Data)
log.Add d.Data
)
p.Start() |> ignore
p.BeginErrorReadLine()
p.BeginOutputReadLine()
p.WaitForExit()

Could you try if starting a process running the paket.exe similarly as done in code above works out of the box? How do you run paket.exe from the command line under your OS?

@iwinux
Copy link
Contributor

iwinux commented Apr 10, 2021

Hi @smoothdeveloper,

It seems that the Paket extension fails to load with the #r "nuget: FSharp.DependencyManager.Paket" line.

In my dotnet fsi session:

> #r "nuget: FSharp.DependencyManager.Paket, 6.0.0-beta8";;
[Loading /var/folders/t3/gn5wn5p97073z3zyb9tzdrxw0000gn/T/nuget/88295--f42862a7-c063-4f87-8c9e-37425413af16/Project.fsproj.fsx]

unknown(1,1): warning FS3186: An error occurred while reading the F# metadata node at position 1 in table 'itycons' of assembly 'FSharp.DependencyManager.Paket, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null'. The node had no matching declaration. Please report this warning. You may need to recompile the F# assembly you are using.

unknown(1,1): warning FS3186: An error occurred while reading the F# metadata node at position 0 in table 'ivals' of assembly 'FSharp.DependencyManager.Paket, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null'. The node had no matching declaration. Please report this warning. You may need to recompile the F# assembly you are using.

Restarting with dotnet fsi --compilertool:"$HOME/.nuget/packages/fsharp.dependencymanager.paket/6.0.0-beta8/lib/netstandard2.0":

> #r "paket: nuget FParsec";;
:paket> using /Users/<username>/.nuget/packages/paket/6.0.0-beta8/tools/paket.exe
exception while resolving dependencies: System.ComponentModel.Win32Exception (8): Exec format error

Running the paket.exe directly from shell:

$ /Users/<username>/.nuget/packages/paket/6.0.0-beta8/tools/paket.exe
zsh: exec format error: /Users/limbo/.nuget/packages/paket/6.0.0-beta8/tools/paket.exe

@iwinux
Copy link
Contributor

iwinux commented Apr 10, 2021

Well, I found the cause - FSharp.DependencyManager.Paket attempts to launch the paket.exe directly, but:

  • dotnet tool install -g paket installs Paket at $HOME/.dotnet/tools/paket, without the .exe extension.

  • $HOME/.nuget/packages/paket/{most-recent-version}/tools/paket.exe cannot be launched because it is not a valid "Mach-O 64-bit x86_64 executable" on macOS.

A quick and dirty fix is cp $HOME/.dotnet/tools/paket $HOME/.dotnet/tools/paket.exe, which brings me some new errors:

> #r "paket: nuget FParsec";;
:paket> using /Users/limbo/.dotnet/tools/paket.exe
:paket> Paket version 6.0.0-beta8
:paket> Resolving dependency graph...
:paket> Installing into projects:
:paket> Created dependency graph (3 packages in total)
:paket> Total time taken: 3 seconds

  #r "paket: nuget FParsec";;
  ^^^^^^^^^^^^^^^^^^^^^^^^^

stdin(1,1): error FS0078: Unable to find the file '/var/folders/t3/gn5wn5p97073z3zyb9tzdrxw0000gn/T/script-packages/673482622/.paket/load/net5.0/main.group.fsx' in any of
 /var/folders/t3/gn5wn5p97073z3zyb9tzdrxw0000gn/T/script-packages/673482622/paket-files
 <current-dir>

@iwinux
Copy link
Contributor

iwinux commented Apr 10, 2021

The path generated by Paket is actually <temp-dir>/.paket/load/net50/main.group.fsx, not <temp-dir>/.paket/load/net5.0/main.group.fsx (net50 v.s. net5.0). Load the file manually, and it seems to work:

> #load "/var/folders/t3/gn5wn5p97073z3zyb9tzdrxw0000gn/T/script-packages/673482622/.paket/load/net50/main.group.fsx";;
[Loading /var/folders/t3/gn5wn5p97073z3zyb9tzdrxw0000gn/T/script-packages/673482622/.paket/load/net50/main.group.fsx]

> FParsec.Text.IsWhitespace ' ';;
Binding session to '/Users/<username>/.nuget/packages/fparsec/1.1.1/lib/netstandard2.0/FParsecCS.dll'...
val it : bool = true

@iwinux
Copy link
Contributor

iwinux commented Apr 10, 2021

A quick fix would be:

diff --git a/src/FSharp.DependencyManager.Paket/ReferenceLoading.PaketHandler.fs b/src/FSharp.DependencyManager.Paket/ReferenceLoading.PaketHandler.fs
index 2b8145e42..c92d93748 100644
--- a/src/FSharp.DependencyManager.Paket/ReferenceLoading.PaketHandler.fs
+++ b/src/FSharp.DependencyManager.Paket/ReferenceLoading.PaketHandler.fs
@@ -14,10 +14,11 @@ open System.IO
 
 let tweakTargetFramework =
     function
+        | "net5.0" -> "net50"
         | "netcoreapp5.0" -> "net50"
         | targetFramework -> targetFramework

@smoothdeveloper
Copy link
Contributor

@iwinux, thanks a lot for going to that extent troubleshooting, the patch seems reasonable, would you mind making a PR with it?

For the other workaround you explain about running of paket.exe, it seems we should have similar logic as the one scanning the folders, but also doing it with the file name, both paket.exe and paket should be tested.

If you have the paket code around, it is not too hard to poke with it in a branch of yours and I can check out your branch to test it on windows to make sure we don't regress on it.

Help appreciated to get it fixed!

@iwinux
Copy link
Contributor

iwinux commented Apr 11, 2021

@smoothdeveloper It's my pleasure to help 😆. Please have a look at #4000 when you have time.

(BTW: it feels difficult to build the whole project on macOS - a lot of errors flying around 🤨. I have to copy FSharp.DependencyManager.Paket to a separate empty repo to make it build successfuly.)

@vilinski
Copy link
Author

now with beta9 it finally works. Thank you @iwinux for investigation!
I have something new, should I care?
no clue what "itycons" or "ivals" tables are

> #r "nuget: FSharp.DependencyManager.Paket, 6.0.0-beta9";;
[Laden /var/folders/89/kmz0d66952vf0kl_f95zcc2m0000gn/T/nuget/94095--c1d6e380-ef8c-4b8e-bb05-d3eebf7ca818/Project.fsproj.fsx]


/Users/username/unknown(1,1): warning FS3186: Beim Lesen des F#-Metadatenknotens an Position 1 in Tabelle "itycons" von Assembly "FSharp.DependencyManager.Paket, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null" ist ein Fehler aufgetreten. Der Knoten besaß keine übereinstimmende Deklarierung. Melden Sie diese Warnung. Sie müssen die von Ihnen verwendete F#-Assembly möglicherweise neu kompilieren.



/Users/username/unknown(1,1): warning FS3186: Beim Lesen des F#-Metadatenknotens an Position 0 in Tabelle "ivals" von Assembly "FSharp.DependencyManager.Paket, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null" ist ein Fehler aufgetreten. Der Knoten besaß keine übereinstimmende Deklarierung. Melden Sie diese Warnung. Sie müssen die von Ihnen verwendete F#-Assembly möglicherweise neu kompilieren.

namespace FSI_0002.Project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants