简体   繁体   中英

F# random class throws BadImageFormatException when calling .NextDouble()

I have made a small application from a book about F#, but when I call the rand.NextDouble() method it throws a BadImageFormatException, which at first glance looks like it's something to do with images so I have NO idea what I'm supposed to do here.

I'm using VS community 2013 using visual F# 2013. I have 64 bit windows 7

I know it's the nextdouble method that's the problem through trying with a seperate let

let create_field num_asteroids =
    let lerp (x: float<'u>) (y:float<'u>) (a:float) =
        x*a+y*(1.0-a)

    let rand = Random()

    [for i =1 to num_asteroids do
        let m =
            (lerp earth_mass moon_mass (rand.NextDouble()))*
            1.0e-4
        let x = lerp 0.0<m> field_size (rand.NextDouble())
        let y = lerp 0.0<m> field_size (rand.NextDouble())
        let vx = max_velocity*(rand.NextDouble()*2.0-1.0)*0.1
        let vy = max_velocity*(rand.NextDouble()*2.0-1.0)*0.1
        yield
            {
            Position = { X = x; Y = y }
            Velocity = { X = vx; Y = vy }
            Mass = m
            Name = "a"
            }
    ]

This is the errorcode:

System.BadImageFormatException was unhandled Message: An unhandled exception of type 'System.BadImageFormatException' occurred in Asteroid_Field_1.exe Additional information: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

MSDN tells me it might have something to with a DLL file not being loaded in the correct format, but I don't even know where to start.

http://pastebin.com/7LhCHr3c

this is the full code

I just tried it in FSI.exe and it works there just fine

I fixed the issue by checking the "optimize code" in the properties of the project in visual studio. I got this fix from a fellow student.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM