fsprojects / FSharp.Azure.Storage

F# API for using Microsoft Azure Table Storage service
MIT License
75 stars 16 forks source link

inTable does not work with internal FSharp record type #6

Closed jackfoxy closed 9 years ago

jackfoxy commented 9 years ago

inTable does not work with internal FSharp record type, only public types.

System.Exception was unhandled
Message: An unhandled exception of type 'System.Exception' occurred in mscorlib.dll
Additional information: Type ConfigurationInsert must be either an ITableEntity or an F# record type

The code in TableStorage.fs

static member val CreateTableOperation = lazy (
    match typeof<'T> with
    | t when typeof<ITableEntity>.IsAssignableFrom t -> createTableOperationFromTableEntity
    | t when FSharpType.IsRecord t -> createTableOperationFromRecord
    | _ -> failwithf "Type %s must be either an ITableEntity or an F# record type" typeof<'T>.Name)

does not recognize the type as FSharpType.IsRecord.

I have short sample project.

daniel-chambers commented 9 years ago

Thanks for reporting this. It's weird that FSharpType.IsRecord would not identify internal record types... it's a built-in F# library function.

I'm currently away at a conference, but when I get back in a few days I'll take a look at this problem.

dsyme commented 9 years ago

You have to give a BindingFlags.Public ||| BindingFlags.NonPublic to the optional binding flags parameter for FSharpType.IsRecord

daniel-chambers commented 9 years ago

That'd do it! Thanks @dsyme!

I'll make a patch and a test for it and push a new nuget as I get a chance.

daniel-chambers commented 9 years ago

This has been fixed and released in v1.0.2

jackfoxy commented 9 years ago

v1.0.2 tested out good for me, thanks