5

I am just beginning with this Mono and .NET stuff, and after reading a bit about F#, I decided to try to follow this simple game tutorial on F# and MonoGame:

http://bruinbrown.wordpress.com/2013/10/06/making-a-platformer-in-f-with-monogame/

After sorting out the many syntax errors of the code I copy-pasted from the blog, I got this code:

module desnovro

open Microsoft.Xna.Framework
open Microsoft.Xna.Framework.Graphics

type Game1 () as x =
    inherit Game()

    do x.Content.RootDirectory <- "Content"
    let graphics = new GraphicsDeviceManager(x)
    let mutable spriteBatch = Unchecked.defaultof<SpriteBatch>

    override x.Initialize() =
        do spriteBatch <- new SpriteBatch(x.GraphicsDevice)
        do base.Initialize()
        ()

    override x.LoadContent() =
        ()

    override x.Update (gameTime) =
        ()

    override x.Draw (gameTime) =
        do x.GraphicsDevice.Clear Color.CornflowerBlue
        ()

[<EntryPoint>]
let main argv =
    use g = new Game1()
    g.Run()
    printfn "Desnovro!!!"
    0

In a MonoDevelop solution I created an F# project with references to:

  • FSharp.Core
  • System
  • System.Core
  • Tao.Sdl
  • MonoGame.Framework.Linux
  • OpenTK

I added the above file, named Program.fs. I am able to successfully compile the project, but when I try to run it, I get the following exception:

Unhandled Exception: System.TypeLoadException: Could not load type 'Game1' from assembly 'game, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'Game1' from assembly 'game, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.

My first attempt was to have the class definition and the main function in separated files (like in the tutorial), but got the same outcome. If I comment out the references to Game1 and g in the main function, the program executes and prints my message "Desnovro!!!" successfully.

What is wrong and how to solve?

I am a complete beginner in this .NET stuff, but I thought that, since I knew Haskell and liked functional programming, it would be quick for me to pick up developing games with MonoGame and F#. I am using Ubuntu 13.10.

lvella
  • 12,754
  • 11
  • 54
  • 106
  • `Microsoft.Xna.Framework` are Microsoft assemblies for the XNA framework - I wouldn't think that you could use them with the references you have there. I'd expect the tutorial to be aimed at the Windows platform. – Oded Nov 16 '13 at 21:20
  • 2
    Microsoft XNA is abandoned and no longer developed game framework. MonoGame is a clone with active development, with many current games released for Linux, Mac and others non-Microsoft platforms. `Microsoft.Xna` namespace is an unfortunate legacy from its Mycrosofty heritagy. – lvella Nov 16 '13 at 21:45
  • Showing my XNA/MonoGame ignorance here, I see. – Oded Nov 16 '13 at 21:45
  • 2
    It might be the case that the assembly loader cannot find some of the referenced assemblies - are they installed in GAC or copied to the output folder with your compiled binary? – Tomas Petricek Nov 17 '13 at 08:46
  • They are installed with apt-get (system wide), I don't know what GAC means and I am not familiar with how library search works on .Net and Mono... – lvella Nov 17 '13 at 15:43
  • 3
    I believe that this is most likely a Mono or MonoGame issue. I tested both your code and my original code on my test machine (Win 8 Pro x64 .Net 4.5 and MonoGame 3.0.1) and it worked. I don't use mono unfortunately but a quick Google search has shown that this might be caused by missing pre-reqs. Can you confirm that you've got OpenAL etc installed? – bruinbrown Nov 17 '13 at 16:53
  • There is most certainly additional error information available. You might try compiling to EXE and then running 'mono --verbose game.exe' to see if you can find the rest of the error. – William Lahti Jul 25 '14 at 23:52
  • Can you include a link to repo with your smaple so that we can see references, etc. The code looks good. – roundcrisis Jan 09 '15 at 11:59

1 Answers1

0

Try defining your Game type in a namespace instead of a module. WPF and C# reflection both can have difficulties locating types inside modules unfortunately.

Maslow
  • 18,464
  • 20
  • 106
  • 193