2
votes

So I stripped the code down to what doesn't work, which is what follows:

[<EntryPoint>]
let main argv = 
  let procStart = new ProcessStartInfo(argv.[0], argv.[1..] |> String.concat " ")
  procStart.RedirectStandardInput <- true
  let proc = Process.Start(argv.[0], argv.[1..] |> String.concat " ")
  let y = Console.ReadLine()
  0

So I started the program with the command line arguments "fsi". fsi is f# interactive, which is on my path, so I'm assuming the absolute path doesn't matter. The program started fine, then it started the fsi process, which started up and shut down after displaying a red error for a split second. I couldn't read the error that fast, so I print screened to get a picture, so there may be a typo or two, but here is the error:

unknown(1,1): error FSI1223: FSharp.Core.sigdata not found alongside FSharp.Core


unknown(1,1): error FS0229: Error opening binary file 'Path\to\project\bin\debug\FSharp.Core': Exception of type 'Microsoft.FSharp.Compiler.ErrorLogger+StopProcessing was thrown.

There was a little bit more about not being able to read the f#.core assembly.

My theory is this: I can start fsi from a normal cmd window; I'm thinking that when I start fsi from cmd, it looks in the same directory as fsi to find f#.core, but when I start it with Process.Start it looks in the current directory for some reason.

I don't know if I'm right, and I don't know how to fix this even if I am.

2
To verify your theory, try setting ProcessStartInfo.WorkingDirectory. - Fyodor Soikin
@FyodorSoikin that solves my issue. I was not aware of that property, thanks. - phil
OK, in that case I will post it as an answer, so people can see it - Fyodor Soikin

2 Answers

0
votes

I'm not sure why this happens exactly, but you can solve it by setting the ProcessStartInfo.WorkingDirectory property to wherever the fsi itself is.

0
votes

Fyoder gave me the clue to the solution, so I accepted his answer, but it was not quite clear enough.

The issue is that fsi and the parent process are trying to use FSharp.Core.dll, which will crash fsi. fsi looks in the current directory first to find the dll, and it finds it, so it assumes it will be ok to use. When `fsi is invoked in a directory that doesn't have the dll, it works fine because it finds the one in the fsi folder.

This should explain why ProcessStartInfo.WorkingDirectory fixes the issue. Note that you can set it to any folder that does not have FSharp.Core.dll in it