F # function in a module showing "Method not found" when called from namespace

I have a function defined in a DataAccess module like this

module DataAccess let getData() = ["abc";"def"] 

Then I use the F # MVC controller to pull the data 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 everything builds well, but when the webpage pops up, it says the method does not exist

 Method not found: 'Microsoft.FSharp.Collections.FSharpList`1<Models.Entity> DataAccess.getData()'. 

When I look at the assembly in dotPeek, it appears as a static method that returns an FSharp list. Did I miss something obvious here?

(Ignore the fact that getData and the map function do nothing, I omitted the code for short, 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 also I have to say that this is MVC 3 with Razor C # pages.

+6
source share
1 answer

Do you have DataAccess and FitnessController defined in the same assembly or different assemblies?

If they are defined in different assemblies, this error is almost certainly caused by an assembly that contains a FitnessController compiled against one version of the assembly containing DataAccess, but a different version is loaded at run time.

This can happen for a number of reasons, two of which I can think of from my head are as follows:

  • A version of the assembly containing DataAccess is deployed to gac. The .NET assembly builder always uses the version deployed in the GAC, if it exists, and it’s quite easy for the version in the GAC to go out of sync with the latest development version.
  • the version of the assembly containing DataAccess is not copied to the bin directory of the asp.net project when compiling your code.

Does this happen in your development environment or in production? If it's in your development environment, it's pretty easy to debug, just run the project in debug mode, then use the Debug> Windows> Modules window to find out where the two assemblies are loading from. Once you find out that it should be pretty easy to see where the problem came from.

Alternatively, it’s easier to just DataAccess and FitnessController enter the same assembly.

+7
source

Source: https://habr.com/ru/post/900388/


All Articles