Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

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

Open
xperiandri opened this issue Jan 7, 2016 · 11 comments
Open

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

xperiandri opened this issue Jan 7, 2016 · 11 comments

Comments

@xperiandri
Copy link

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()
@Alxandr
Copy link
Contributor

Alxandr commented Jan 8, 2016

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

@xperiandri
Copy link
Author

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

@Alxandr
Copy link
Contributor

Alxandr commented Jan 8, 2016

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?

@xperiandri
Copy link
Author

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

@Alxandr
Copy link
Contributor

Alxandr commented Jan 8, 2016

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)?

@xperiandri
Copy link
Author

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

@Alxandr
Copy link
Contributor

Alxandr commented Jan 8, 2016

Try nuking the artifacts folder.

@xperiandri
Copy link
Author

What do you mean by that?

@Alxandr
Copy link
Contributor

Alxandr commented Jan 8, 2016

Delete it

@CumpsD
Copy link

CumpsD commented Feb 3, 2016

Can be related to #28 I had the same error

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

@Ciantic
Copy link

Ciantic commented Feb 16, 2016

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.

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

No branches or pull requests

4 participants