F# is unable to find external types

I have got a specific problem while making some exercises from “A Functional Architecture with F#”, a great F# course by Mark Seemann. After adding a controller (Controller.fs), a file with types (Rendition.fs) and using an external type inside controller, the compiler started to say that this external type is not defined. It looks good at first sight. Names and namespaces are exactly the same.


namespace Ploeh.Samples.Booking.HttpApi

open System
open System.Net
open System.Net.Http
open System.Web.Http

type HomeController() =
    inherit ApiController()
        member this.Get() = new HttpResponseMessage()

type ReservationsController() =
    inherit ApiController()

    member this.Post (rendition : MakeReservationRendition) =
        new HttpResponseMessage(HttpStatusCode.Accepted)

There is controller (Controller.fs) code above. Visual Sudio marks MakeReservationRendition red and says that this type is not defined. But it is. Below is Rendition.fs file code whit this type defined.


namespace Ploeh.Samples.Booking.HttpApi

open System

[<CLIMutable&amp;gt;]
type MakeReservationRendition = {
    Date : string
    Name : string
    Email : string
    Quantity : int }

As you can see the namespace is good, so this code should be compiled without any problems. I have started to compare my code with exercise files on Pluralsight. Everything looked the same. I have tried to examine project files (fsproj). ItemGroup node looked looked strange…


<ItemGroup>
    <Compile Include="AssemblyInfo.fs" />
    <Compile Include="Infrastructure.fs" />
    <Content Include="packages.config" />
    <Compile Include="Controller.fs" />
    <Compile Include="Rendition.fs" />
</ItemGroup>

In exercise files Rendition.fs was above Controller.fs. I have changed this in my project file. It worked!

There are no such problems in C#, so it wasn’t obvious. Of course it is not a good solution, but it helped me to continue my exercises.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*
Website