mbraceproject / FsPickler

A fast multi-format message serializer for .NET
http://mbraceproject.github.io/FsPickler/
MIT License
326 stars 52 forks source link

Xamarin Support #25

Closed TIHan closed 6 years ago

TIHan commented 10 years ago

Right now, FsPickler isn't a PCL library and I don't know if it can be. It it can, it will be easy to have it work for Xamarin iOS + Android.

I have a prototype branch of FsPickler on Xamarin here: https://github.com/TIHan/FsPickler/tree/xamarin. It will only work if you have OSX and Xamarin Studio + iOS/Android SDKs installed. These are platform specific projects. Just open FsPickler.Mac.sln and look at the src directory. FsPickler.Touch + FsPicker.Droid.

I do not know what else is necessary for this to happen, but I figure, this is a good start.

eiriktsarpalis commented 10 years ago

In principle, it should be possible to do this. Importantly, a PCL version should be built with the EMIT_IL flag disabled, as FsPickler by default uses dynamic methods for performance. Somebody actually mentioned on twitter some time ago that he was able to work with a custom FsPickler build on Xamarin.

Ideally, I would like to see a portable build included with the nuget package. It should be possible to build a package on any platform and without Xamarin dependencies. I have included a NoEmit build configuration with the intension of eventually producing portable assemblies but there is still work to be done there.

Thoughts?

TIHan commented 10 years ago

PCL is probably the best path to go with this. You can't create PCL F# projects in Xamarin Studio, but of course we have Visual Studio to do that for us. When I get a chance, I'll look at a PCL build of FsPickler to see what's there and to see if it's do-able.

TIHan commented 10 years ago

I did some exploring on the PCL path. Seems there would need to be a good bit of re-writes to support PCL. While this is a preferred path, it will also take the longest.

C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Utils.fs(11,33): error FS0039: The namespace 'Concurrent' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Utils.fs(39,23): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Utils.fs(39,50): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Utils.fs(40,44): error FS0039: The field, constructor or member 'GetField' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Utils.fs(42,48): error FS0039: The field, constructor or member 'GetField' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Utils.fs(111,29): error FS0039: The type 'ConcurrentDictionary' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Utils.fs(112,22): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Utils.fs(117,29): error FS0039: The type 'ConcurrentDictionary' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Utils.fs(118,30): error FS0039: The type 'ConcurrentDictionary' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Utils.fs(121,32): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Utils.fs(125,21): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Utils.fs(133,32): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Utils.fs(137,21): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Utils.fs(145,14): error FS0039: The type 'SerializationInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Utils.fs(185,43): error FS0001: The type 'string' is not compatible with the type 'seq<'a>' C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(10,9): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(10,36): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(11,13): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(11,39): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(14,9): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(14,36): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(15,13): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(15,39): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(16,17): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(18,21): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(18,48): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(18,72): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(20,27): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(20,53): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(20,80): error FS0039: The namespace or module 'BindingFlags' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(24,44): error FS0001: The type ''a * 'b' is not compatible with the type 'MethodInfo' C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(24,43): error FS0193: Type constraint mismatch. The type  'a * 'b is not compatible with type MethodInfo The type ''a * 'b' is not compatible with the type 'MethodInfo' C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(24,13): warning FS0067: This type test or downcast will always hold C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(24,13): error FS0008: This runtime coercion or type test from type 'T  to  'T involves an indeterminate type based on information prior to this program point. Runtime type tests are not allowed on some types. Further type annotations are needed. C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(29,15): error FS0039: The field, constructor or member 'GetMethods' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(31,17): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(32,24): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(33,42): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(34,37): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(37,25): error FS0039: The field, constructor or member 'GetConstructor' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(70,46): error FS0001: The type ''a * 'b' is not compatible with the type 'MethodInfo' C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(70,45): error FS0193: Type constraint mismatch. The type  'a * 'b is not compatible with type MethodInfo The type ''a * 'b' is not compatible with the type 'MethodInfo' C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(70,22): error FS0008: This runtime coercion or type test from type 'a  to  'Dele involves an indeterminate type based on information prior to this program point. Runtime type tests are not allowed on some types. Further type annotations are needed. C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(78,24): error FS0039: The field, constructor or member 'IsAssignableFrom' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(80,22): error FS0039: The field, constructor or member 'BaseType' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(84,62): error FS0039: The type 'ISerializable' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(100,11): error FS0039: The field, constructor or member 'IsGenericType' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(109,29): error FS0039: The field, constructor or member 'GetMembers' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(111,25): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(116,21): error FS0039: The field, constructor or member 'BaseType' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(133,60): error FS0039: The field, constructor or member 'IsNotSerialized' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(159,18): error FS0039: The field, constructor or member 'IsGenericType' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(190,14): error FS0039: The field, constructor or member 'IsGenericType' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(202,74): error FS0039: The type 'DBNull' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(206,18): error FS0039: The field, constructor or member 'IsPrimitive' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(208,37): error FS0039: The field, constructor or member 'IsAssignableFrom' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(232,24): error FS0039: The field, constructor or member 'IsSealed' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(250,18): error FS0039: The field, constructor or member 'IsPrimitive' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\Reflection.fs(251,37): error FS0039: The field, constructor or member 'IsAssignableFrom' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Utils\ShallowCopy.fs(15,18): error FS0039: The field, constructor or member 'IsValueType' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(63,20): error FS0039: The field, constructor or member 'IsPrimitive' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(65,20): error FS0039: The field, constructor or member 'IsEnum' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(67,20): error FS0039: The field, constructor or member 'IsValueType' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(69,20): error FS0039: The field, constructor or member 'IsSealed' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(70,20): error FS0039: The field, constructor or member 'IsAbstract' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(116,32): error FS0039: The field, constructor or member 'CultureInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(150,31): error FS0039: The field, constructor or member 'CultureInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(151,29): error FS0039: The field, constructor or member 'CultureInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(204,28): error FS0039: The type 'SerializationInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(204,28): error FS0039: The type 'SerializationInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(205,37): error FS0001: The type 'StreamingContext' is not compatible with the type 'exn' C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(205,37): error FS0193: Type constraint mismatch. The type  StreamingContext is not compatible with type exn The type 'StreamingContext' is not compatible with the type 'exn' C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(214,28): error FS0039: The type 'SerializationInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(214,28): error FS0039: The type 'SerializationInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(225,28): error FS0039: The type 'SerializationInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(225,28): error FS0039: The type 'SerializationInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(252,19): error FS0039: The type 'ISerializable' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(252,19): error FS0887: The type 'obj' is not an interface type C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(252,19): error FS0039: The type 'ISerializable' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(252,19): error FS0039: The type 'ISerializable' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(252,19): error FS0908: This type is not an interface type C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(246,28): error FS0039: The type 'SerializationInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(253,22): error FS0855: No abstract or interface member was found that corresponds to this override C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(253,41): error FS0039: The type 'SerializationInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(246,28): error FS0039: The type 'SerializationInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(249,27): error FS0039: The field, constructor or member 'Read' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(253,41): error FS0039: The type 'SerializationInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(254,22): error FS0039: The field, constructor or member 'GetObjectData' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(255,17): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(297,19): error FS0039: The type 'ISerializable' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(297,19): error FS0887: The type 'obj' is not an interface type C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(297,19): error FS0039: The type 'ISerializable' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(297,19): error FS0039: The type 'ISerializable' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(297,19): error FS0908: This type is not an interface type C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(290,19): error FS0039: The type 'SerializationInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(298,22): error FS0855: No abstract or interface member was found that corresponds to this override C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(298,41): error FS0039: The type 'SerializationInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(290,19): error FS0039: The type 'SerializationInfo' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(293,27): error FS0039: The field, constructor or member 'Read' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(294,52): error FS0039: The field, constructor or member 'Read' is not defined C:\Users\willsmith\Documents\GitHub\FsPickler\src\FsPickler.PCL\Pickler\Types.fs(298,41): error FS0039: The type 'SerializationInfo' is not defined

It is much easier to have a platform specific DLL for iOS and Android.

eiriktsarpalis commented 10 years ago

I think you have sufficiently proved that PCL is out of the question for FsPickler. The missing reflection types are essential for the library to work.

Have you tried using a NoEmit build with Xamarin? I would be interested to see if this works.

TIHan commented 10 years ago

I believe the projects in my xamarin branch do not include any specific defines related to FsPickler. Because the projects do not have the "EMIT_IL" define, it is essentially a NoEmit build.

eiriktsarpalis commented 10 years ago

Ok, but can it still work without having dependencies on Xamarin's SDK?

TIHan commented 10 years ago

It doesn't use anything iOS or Android specific. The two projects, Touch and Droid, must require their respective platform dependencies, such as MonoTouch and MonoDroid, in order to compile the platform specific library.

eiriktsarpalis commented 10 years ago

Ah, understood. I will install the SDK as soon as I find the time to get a feel for the process myself.