views:

435

answers:

2

I managed to cobble together a suitable implementation of a sample game in F# with xna. However when i try to instantiate my derived game class, the code throws a FileNotFound exception trying to access the Microsoft.Xna.Framework assembly. Why does this happen?

Code:

#light
open System
open Microsoft.Xna.Framework
open Microsoft.Xna.Framework.Audio
open Microsoft.Xna.Framework.Content
open Microsoft.Xna.Framework.Design
open Microsoft.Xna.Framework.GamerServices
open Microsoft.Xna.Framework.Graphics
open Microsoft.Xna.Framework.Input

type SampleGame() as self =
    class
    inherit Game()
    let mutable manager : GraphicsDeviceManager = null
    let mutable spriteBatch : SpriteBatch = null
    do
        manager <- new GraphicsDeviceManager(self)
    override Game.Initialize() = 
        base.Initialize()
    override Game.LoadContent() = 
        spriteBatch <- new SpriteBatch(manager.GraphicsDevice)
        base.LoadContent()
    override Game.Update(gameTime) = 
        base.Update(gameTime)
        if GamePad.GetState(PlayerIndex.One).Buttons.Back = ButtonState.Pressed then
            self.Exit()
    override Game.Draw(gameTime) = 
        manager.GraphicsDevice.Clear(Color.CornflowerBlue);
        base.Draw(gameTime)
    end

let game = new SampleGame()
game.Run()

I have added the proper references by the way. Edit: after some exploration, i found that my F# project is being compiled to 64 bit, which does not work with the 32 bit XNA dlls. However VS 2010 doesnt let me change the solution platform. How do i fix this?

+2  A: 

I don't know enough about XNA, but is it 'in the GAC', or do you need to copy the XNA dlls next to your .exe? It sounds like perhaps having Microsoft.Xna.Framework.dll next to your .exe may solve it.

EDIT

Based on the 32/64-bit info, perhaps manually change the "<Platform>" in the .fsproj file. (Right click the project, 'Unload Project', then right click again and 'Edit Whatever.fsproj', poke the XML to have 'x86' (rather than 'x64' or 'AnyCPU') as the Platform value, save, and right click project and 'Reload'.) (Various F# bugs in Beta1 conspire to make the Platform/SolutionConfiguration-experience less than optimal.)

Brian
For those interested in what's happening in more detail:http://blogs.msdn.com/shawnhar/archive/2008/02/25/xna-framework-on-64-bit-windows.aspx
jasonh
That sadly did not work.
RCIX
After some more poking around i got it to work. Thanks!
RCIX
See also stuff mentioning F# in http://download.microsoft.com/download/7/A/0/7A023209-096F-4F7D-B2BC-831ECC68FF5B/VS2010Beta1Readme.htm
Brian
+1  A: 

Check this article, which should give you an idea on how to implement this in F# http://www.xnawiki.com/index.php?title=XNA%5Fin%5FVB%5F.Net

vbSetev