neuecc / Utf8Json

Definitely Fastest and Zero Allocation JSON Serializer for C#(NET, .NET Core, Unity, Xamarin).
MIT License
2.36k stars 266 forks source link

Operation is not supported on this platform. Xamarin Forms iOS #74

Closed kevinvella closed 6 years ago

kevinvella commented 6 years ago

Hi,

I was trying the PureSocketCluster library. Internally it uses Utf8Json. When i run it on iOS it gives me an Operation is not supported on this platform.

Running it on Xamarin.Android it works very well.

Versions: Utf8Json - v1.3.7 Xamarin Forms - v2.5.1.444934

Hope this can help Attaching some screenshots of the stack trace screen shot 2018-04-27 at 10 40 16 screen shot 2018-04-27 at 10 40 09 screen shot 2018-04-27 at 10 40 02 screen shot 2018-04-27 at 10 39 55 screen shot 2018-04-27 at 10 39 48 screen shot 2018-04-27 at 10 39 41 screen shot 2018-04-27 at 10 39 35

neuecc commented 6 years ago

for iOS, required precode generation. see: https://github.com/neuecc/Utf8Json#pre-code-generationunityxamarin-supports

kevinvella commented 6 years ago

@neuecc Ok. One question. How should i generate the resolvers for PureSocketCluster?

neuecc commented 6 years ago

related to https://github.com/Coinigy/PureSocketCluster/issues/8 ? It seems to serialize Dictionary<string, object>. https://github.com/Coinigy/PureSocketCluster/blob/master/src/PureSocketCluster/PureSocketClusterSocket.cs

I think configure and use include PrimitiveObjectFormatter, maybe works.

kevinvella commented 6 years ago

Yes i created an issue on their repo.

I am trying to get the universal code generator to work / figuring it out.

For the PrimitiveObjectFormatter, you saying something like this?

Utf8Json.Resolvers.CompositeResolver.RegisterAndSetAsDefault(
      // use generated resolver first, and combine many other generated/custom resolvers
      Utf8Json.Resolvers.DynamicCompositeResolver.Create(
            new Utf8Json.IJsonFormatter[] { PrimitiveObjectFormatter.Default  }
            ,new Utf8Json.IJsonFormatterResolver[] { Utf8Json.Resolvers.StandardResolver.Default }
      )
);
kevinvella commented 6 years ago

If i use Utf8Json.Resolvers.CompositeResolver.RegisterAndSetAsDefault(new Utf8Json.IJsonFormatter[] { PrimitiveObjectFormatter.Default });

I get this screen shot 2018-04-27 at 13 53 15

neuecc commented 6 years ago

You can set like following.

Utf8Json.Resolvers.CompositeResolver.RegisterAndSetAsDefault(
    new [] { PrimitiveObjectFormatter.Default },
    new [] { Utf8Json.Resolvers.StandardResolver.Default }
);
kevinvella commented 6 years ago

Using the above i get the same platform not support exception.

The type initializer for 'Utf8Json.Resolvers.Internal.DynamicObjectResolverAllowPrivateFalseExcludeNullFalseNameMutateOriginal' threw an exception.

Will continue trying to work out the universal code generator

neuecc commented 6 years ago

How about this?

Utf8Json.Resolvers.CompositeResolver.RegisterAndSetAsDefault(
    new [] { PrimitiveObjectFormatter.Default },
    new Utf8Json.IJsonFormatterResolver[] 
    {
        // + code generator resolver(serialize custom type)

        Utf8Json.Resolvers.BuiltinResolver.Instance,
        // EnumResolver.Default,(can't serialize enum...)
        Utf8Json.Resolvers.DynamicGenericResolver.Instance,
        Utf8Json.Resolvers.AttributeFormatterResolver.Instance
    }
);
ByronAP commented 6 years ago

beat me to it

ByronAP commented 6 years ago

I will externalize the deserializer interface to allow modifications

kevinvella commented 6 years ago

Holy cow. This works! :D :D

Receiving data from the websocket. Will try to send data shortly.

Thanks very much for this!!! I'm in your debt hahaha