Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

f# console app doesn't work. c# console app does

Tags:

c#

console

f#

I am attempting to deploy a simple f# console app to a coworkers computer but it keeps failing. After double clicking on the app icon, the console window appears but then the Microsoft error reporting window shows up asking if I would like to send the error report, I decline then some text flashes in the console window. It looks like an error message, but the window closes too fast to tell. The weird thing is, if I create a similar C# app, it works. I am targeting .net 4 client framework in release mode.

Here is the code

f# code (doesn't work):

open System

printfn "print test"
Console.ReadLine() |> ignore

c# code (does work):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestCApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Testing...");
            Console.ReadLine();
        }
    }
}
like image 667
Brad Avatar asked Sep 09 '26 12:09

Brad


2 Answers

The F# analog of your C# snippet would be not your F# code, but the following:

System.Console.WriteLine "print test"
System.Console.ReadLine() |> ignore

While the app off 2-liner above will run, similarly to one off your C# snippet, just on raw .NET, use of printfn function in your F# code requires certain F#-specific core components being deployed on the target computer, which is likely not the case. The latter explains the observed behavior.

like image 64
Gene Belitski Avatar answered Sep 11 '26 02:09

Gene Belitski


Look at the references of your F# project and you will see one to FSharp.Core which is normally located here:

C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\2.0\Runtime\v4.0\FSharp.Core.dll

On Windows 7 (64 bit) PC

Also look at the F# site to get the runtime download.

http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/release.aspx

EDIT: here is the direct link to the runtime download (thanks ildjarn):

http://www.microsoft.com/en-us/download/details.aspx?id=13450

like image 40
Carlos Quintanilla Avatar answered Sep 11 '26 00:09

Carlos Quintanilla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!