Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reflection error when using F# sprintf "%A" on Windows Phone

I have a set of F# record types like this:

type Course =
    { Id : int
      Title : string
      Instructor : string
      Duration : string
      StartDate : string
      IconUrl : string
      Url : string 
      LectureSections : LectureSection list }

and LectureSection =
    { Title : string
      Completed : bool
      Lectures : Lecture list }

and Lecture = 
    { Title : string
      VideoUrl : string }

and at some point I call

sprintf "%A" course

where course is an instance of the Course record

On a regular .NET project this works fine, but on a Windows Phone 7.1 / Silverlight 4 F# project (I'm using Daniel Mohl's templates), I get this error:

Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.

The problem seems to be the lists. Does anyone know of any way around this problem?

like image 558
Gustavo Guerra Avatar asked Nov 05 '22 00:11

Gustavo Guerra


1 Answers

The templates should come with a custom built FSharp.Core.dll that disable features that are not available on Windows Phone. Are you sure you are compiling against this dll, and not the Windows PC one?

I had similar problems with Xbox360 and XNA. The F# team sent me a dll suitable for use for the Xbox360, along with some brief instructions on the settings used to build the dll.

Here is the propertygroup we've used to compile FSharp.Core:

 <PropertyGroup Condition="'$(TargetFramework)'=='Xbox360\CompactFramework\3.7'">
   <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
   <TargetFrameworkProfile>Client</TargetFrameworkProfile>
   <XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
   <XnaPlatform>Xbox 360</XnaPlatform>
   <XnaProfile>HiDef</XnaProfile>
   <XnaCrossPlatformGroupID>a8d70e6b-9a75-4aec-80f8-62cf373f7368</XnaCrossPlatformGroupID>
   <XnaOutputType>Game</XnaOutputType>
   <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
   <DefineConstants>$(DefineConstants);FX_NO_ARRAY_LONG_LENGTH;FX_NO_DEBUG_PROXIES;FX_NO_EXIT;FX_FSLIB_IOBSERVABLE;FX_NO_WEB_CLIENT;FX_NO_WEB_REQUESTS;FX_NO_CHAR_PARSE;FX_NO_DEFAULT_DEPENDENCY_TYPE;FX_SIMPLE_SECURITY_PERMISSIONS;FX_NO_TRUNCATE;FX_NO_CULTURE_INFO_ARGS;FX_NO_REFLECTION_MODULE_HANDLES;FX_NO_OPERATION_CANCELLED;FX_NO_TO_LOWER_INVARIANT;FX_NO_EXIT_CONTEXT_FLAGS;FX_NO_BASED_ARRAYS;FX_NO_DOUBLE_BIT_CONVERTER;FX_NO_BINARY_SERIALIZATION;FX_NO_ASCII_ENCODING;FX_NO_DEFAULT_ENCODING;FX_NO_FILE_OPTIONS;FX_NO_NONBLOCK_IO;FX_NO_COMMAND_LINE_ARGS;FX_NO_ENVIRONMENT;FX_NO_PROCESS_START;FX_NO_APP_DOMAINS;FX_NO_PROCESS_DIAGNOSTICS;FX_FSLIB_STRUCTURAL_EQUALITY;FX_FSLIB_LAZY;FX_FSLIB_TUPLE;FX_NO_REFLECTION_EMIT</DefineConstants>
   <Tailcalls>false</Tailcalls>
   <!-- It would be better to use MSBuild resolution here, but the TargetFrameworkIdentifier etc. aren't set up quite correctly as yet -->
   <OtherFlags>$(OtherFlags) --simpleresolution -r:"C:\Program Files\Microsoft XNA\XNA Game Studio\v4.0\References\Xbox360\mscorlib.dll"</OtherFlags>
 </PropertyGroup>

and the new .targets we use:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\Microsoft.Xna.GameStudio.targets" Condition="'$(TargetFramework)'=='Xbox360\CompactFramework\3.7'"/>

The dll they sent me was working fine, and I never had to use these instructions, but they might be useful to someone who wants to build an FSharp.Core.dll for a new platform. Note in particular the DefineConstants part.

like image 127
Joh Avatar answered Nov 09 '22 15:11

Joh