kevin-montrose / Jil

Fast .NET JSON (De)Serializer, Built On Sigil
MIT License
2.15k stars 253 forks source link

Support for Xamarin #301

Open rusty21 opened 6 years ago

rusty21 commented 6 years ago

I'm looking to use Jil inside of some our xamarin applications but after installing the package on a xamarin android project I receive the error on build

>/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2,2): Error: Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'System.Runtime.InteropServices.PInvoke, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'System.Runtime.InteropServices.PInvoke.dll'
  at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference reference, Mono.Cecil.ReaderParameters parameters) [0x00099] in /Users/builder/data/lanes/5809/22d97e15/source/monodroid/external/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:229 
  at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference reference) [0x00000] in /Users/builder/data/lanes/5809/22d97e15/source/monodroid/external/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:179 
  at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver resolver, System.Collections.Generic.ICollection`1[T] assemblies, Mono.Cecil.AssemblyDefinition assembly, System.Boolean topLevel) [0x0015c] in <6633a024ed374c909823f5db22e5904c>:0 
  at Xamarin.Android.Tasks.ResolveAssemblies.Execute (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver resolver) [0x001c7] in <6633a024ed374c909823f5db22e5904c>:0  (MetalWorks.Android)

Should this not just work with xamarin supporting netstandard, and Jil supporting netstandard?

NickCraver commented 6 years ago

Jil relies heavily on IL generation and this just isn't something that Xamarin supports (on most of the target platforms you'd use it on). We get similar requests for Dapper, but until something like Roslyn code generators are added as a feature, it's just impractical to support.

rusty21 commented 6 years ago

That makes me a little sad. It would be nice to have an alternative to Newtonsoft. Jil's speed was a huge attraction for us as we have the need to serialize and deserialize tens of thousands of objects quite frequently. Newtonsoft wasn't giving us the performance we were looking for. I don't know much about this, but IL generation (intermediate language generation?) is what gives Jil its speed over just using reflection? I don't know whats special about IL generation and why xamarin would need to support it. I'd be curious if you had a way to explain it to a not so smart person :)

NickCraver commented 6 years ago

I'm not an expert here, but my understanding is those platforms will never allow it, because any form of metaprogramming (creating new functionality on the fly) is something really unwanted. For example, if you created some functionality that activated after an app store review, they'd be pissed. On the technical side, they're also just compiling past the IL phase and into the local platform level anyway...so there's nothing to interpret the IL if it were generated (that phase happened when the developer built the app, for most or all platforms).