System.Linq.Expressions.Interpreter.CastReferenceToEnumInstruction.Run throws error in iOS

IanSinglehurstIanSinglehurst GBUniversity ✭✭

Hello all.
We are trying to re-release our iOS app after making changes to it's Droid and WinPhone counterparts when this error was uncovered.
None of the old base code has been changed only some platform specific stuff for the aforementioned phones.

What we are doing is making a request to a web response, then deserialising the response into an object. see code snippet below.

HttpResponseMessage response = await client.GetAsync(new Uri(url), cancellationToken);
string responseStringContent = await response.Content.ReadAsStringAsync();
var returnedObject = JsonConvert.DeserializeObject<T>(responseStringContent);

In this case T is the following class

public class Question
        [JsonProperty(PropertyName = "Identity")]
        public override long Id { get; set; }

        public int Order { get; set; }

        [JsonProperty(PropertyName = "Content")]
        public string QuestionText { get; set; }

        [JsonProperty(PropertyName = "Number")]
        public string QuestionNumber { get; set; }

    [JsonProperty(PropertyName = "Type")]
        public QuestionTypeEnum QuestionType { get; set; }

The enum is as follows

public enum QuestionTypeEnum
            Multiple = 0,
            Single = 1

The error thrown is
Error setting value to 'QuestionType' on 'Conservatives.Mobile.Model.Question'
With an Inner exception of
System.InvalidCastException: Specified cast is not valid.
at System.Linq.Expressions.Interpreter.CastReferenceToEnumInstruction.Run (System.Linq.Expressions <---then this bit is cut off on iPhone simulator

I've had a log at the whole Json string sent by the server and it only have values 0 and 1 for the Type so that is not the problem.
Additionally the old iOS version of the app continues to work as do the two other Droid and WinPhone versions.

Has anyone had something like this happen before?
Any suggestions?

Kind Regards

Sign In or Register to comment.