zzarchive-fsharp-dnx icon indicating copy to clipboard operation
zzarchive-fsharp-dnx copied to clipboard

Do you know how to run F# with DNX RC2?

Open xperiandri opened this issue 9 years ago • 11 comments

I tried different ways

type public Program =
  static member public Main (args: string array) =
    let runtimeFramework = PlatformServices.Default.Application.RuntimeFramework
    printfn "Hello from F#, running on %s v%s" runtimeFramework.Identifier (runtimeFramework.Version.ToString ())
    System.Console.ReadKey() |> ignore
    0

or

type Program =
  static member public Main () =
    let runtimeFramework = PlatformServices.Default.Application.RuntimeFramework
    printfn "Hello from F#, running on %s v%s" runtimeFramework.Identifier (runtimeFramework.Version.ToString ())
    System.Console.ReadKey() |> ignore

but receive

System.MissingMethodException: No parameterless constructor defined for this object.
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck,
 Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at Microsoft.Dnx.Runtime.Common.DependencyInjection.ActivatorUtilities.<>c__DisplayClass4_1.<Crea
teFactory>b__1(IServiceProvider _)
   at Microsoft.Dnx.Runtime.Common.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider services, Type type)
   at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.TryGetEntryPoint(Assembly assembly, IServiceProvider serviceProvider, Object& instance, MethodInfo& entryPoint)
   at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
   at Microsoft.Dnx.ApplicationHost.Program.<>c__DisplayClass3_0.<ExecuteMain>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()

xperiandri avatar Jan 07 '16 20:01 xperiandri

The most likely cause of MissingMethodExceptions is conflicting versions of libraries and/or DNX itself. Make sure they are the same.

Alxandr avatar Jan 08 '16 04:01 Alxandr

What do I have to check? I did dnvm upgrade -u

Determining latest version
'dnx-clr-win-x86.1.0.0-rc2-16357' is already installed in C:\Users\Андрій\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc2-16357.
Adding C:\Users\Андрій\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc2-16357\bin to process PATH
Adding C:\Users\Андрій\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc2-16357\bin to user PATH
Updating alias 'default' to 'dnx-clr-win-x86.1.0.0-rc2-16357'

Then I do C:\Users\Андрій\Dev\GitHub\fsharp-dnx\sample\HelloFSharp>"C:\Users\Андрій\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc2-16357\bin\dnx" run And get that stack trace. C:\Users\Андрій\Dev\GitHub\fsharp-dnx\sample\HelloFSharp>"C:\Users\Андрій\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc2-16379\bin\dnx" run does not work too

Running from Visual Studio produces the same result and console windows closes.

I also tried to create C# MVC 6 app (WebApplication1) and reference F# MVC 6 library (WebApplication2) but get

The design time host build failed with the following error: Unable to cast object of type 'FSharp.Dnx.FSharpProjectCompiler' to type 'Microsoft.Dnx.Compilation.IProjectCompiler'. n WebApplication1 and WebApplication2    C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DNX\Microsoft.DNX.targets 166

I have no idea what is wrong

xperiandri avatar Jan 08 '16 10:01 xperiandri

VS is wonky, so don't expect much F# DNX to work from there. You have to run from command line.

Also, don't use full path when executing DNX. I'm not sure if this matters, but in case it uses PATH to find relevant libraries it might. So after selecting a DNX version (as you have by doing dnvm upgrade -u) simply do dnx run. If you want to see which version of DNX is currently enabled, do dnx --version.

After doing dnx upgrade (or switching dnx any other way), it's important you do dnu restore.

Now, you've showed me what version of DNX you're using, but that's only half of the story. Though, since you're running the HelloFSharp sample, I'm assuming you've not modified neither the NuGet.Config nor project.json file?

Alxandr avatar Jan 08 '16 12:01 Alxandr

I only tried with "FSharp.Compiler.Service": "1.4.0.6" and with "FSharp.Compiler.Service": "2.0.0.2" (the only change)

xperiandri avatar Jan 08 '16 13:01 xperiandri

So you've restored everything (you have to do this at the solution root for this project I think) after making sure you have the latest DNX selected (checking dnx --version)?

Alxandr avatar Jan 08 '16 13:01 Alxandr

C:\Users\Андрій\Dev\GitHub\fsharp-dnx\sample\HelloFSharp> dnx --version
Microsoft .NET Execution environment
 Version:      1.0.0-rc2-16357
 Type:         Clr
 Architecture: x86
 OS Name:      Windows
 OS Version:   6.3.9600
 Runtime Id:   win81-x86

Only this error in HelloMvc with dnu restore nothing else

Errors in C:\Users\Андрій\Dev\GitHub\fsharp-dnx\artifacts\bin\HelloMvc\Debug\app\project.json
    Unable to locate Dependency HelloMvc >= 1.0.0-beta

xperiandri avatar Jan 08 '16 13:01 xperiandri

Try nuking the artifacts folder.

Alxandr avatar Jan 08 '16 15:01 Alxandr

What do you mean by that?

xperiandri avatar Jan 08 '16 15:01 xperiandri

Delete it

Alxandr avatar Jan 08 '16 15:01 Alxandr

Can be related to https://github.com/fsprojects/fsharp-dnx/pull/28 I had the same error

You need type Program() = mind the braces for the parameterless constructor of Program

CumpsD avatar Feb 03 '16 23:02 CumpsD

I got this working with running "dnvm upgrade -u" then "dnu restore" in root folder and then "dnu restore" in the chosen sample folder, and then "dnx run". (HelloFSharp sample works with these commands, HelloMvc is broken as mentioned above)

Though would be nice if FSharp.Dnx were available in the nuget, if it is I couldn't get it working from there.

Ciantic avatar Feb 16 '16 09:02 Ciantic