5

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?

Gustavo Guerra
  • 5,319
  • 24
  • 42
  • 1
    An obvious workaround is to override `ToString()` member and use `sprintf "%O"` :) – pad May 07 '12 at 18:21

1 Answers1

2

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.

Joh
  • 2,380
  • 20
  • 31
  • I'm linking to the custom built FSharp.Core.dll that comes in the template. I can try to recompile FSharp.Core from source to see if it solves the problem. There's also two extra files on the template - FSharp.Core.optdata and FSharp.Core.sigdata - I'm not sure what they are and if I need to also regenerate them or not – Gustavo Guerra May 08 '12 at 22:54
  • Maybe a bug in the handling of %A in FSharp.Core? If you search for the error message, http://stackoverflow.com/questions/3843042/invoking-a-method-of-a-generic-class shows up. People who forget the call to `MakeGenericType` get this error. – Joh May 09 '12 at 05:46
  • I replaced the FSharp.Core file that comes in the template by the one that comes in the [F# April 2011 CTP](http://www.microsoft.com/en-us/download/details.aspx?id=11100) in the WindowsPhone7\Silverlight\4.0\bin folder, and while it solved [another problem I was having](http://stackoverflow.com/questions/10486311/f-quotations-on-windows-phone/10558374), I still get this exception on %A – Gustavo Guerra May 11 '12 at 20:48