I have a function defined in a module called DataAccess like this
module DataAccess
let getData() =
["abc";"def"]
I'm then using an F# MVC controller to pull the data out like this
[<HandleError>]
type FitnessController() =
inherit Controller()
member x.Index() =
let data = DataAccess.getData() |> List.map(fun p -> p) |> List.toArray
x.View(data) :> ActionResult
I get intellisense and all builds well, but when the web page pops up it says that the method does not exist
Method not found: 'Microsoft.FSharp.Collections.FSharpList`1<Models.Entity> DataAccess.getData()'.
When I take a look at the assembly in dotPeek it does show up as a static method that returns an FSharp list. Am I missing something obvious here?
(Ignore the fact that getData and the map function do nothing i've omitted the code for brevity, getData just contains record types that are marked as serializable, but I still get the error even when using strings as in the code example here) I should also say that this is MVC 3 with Razor C# pages.
Do you have DataAccess and FitnessController defined in the same assembly or different assemblies?
If they are defined in different assemblies then this error is almost certainly caused by the assembly that contains FitnessController being compiled against one version of the assembly that contains DataAccess but at runtime a different version is loaded.
This could happen for a number of reasons, the two that I can think of off the top of my head are:
Is this happen in your development environment or in production? If it's in your development environment it should be fairly easy to debug, simple run the project in debug mode then use the Debug > Windows > Modules window to see where the two assemblies are being loaded from. Once you know that it should be fairly easy to see where the problem comes from.
Alternatively it may just be easier DataAccess and FitnessController into the same assembly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With