1
votes

I am trying to get the following code to work, but a not implemented exception get thrown when I try to Serialize the object. It states "The method or operation is not implemented." I have tried implementing ITweet as a concrete class, but I can not go from the interface to concrete class.

private void SendToKinesis(ITweet tweet)
    {


        var dataAsJson = JsonConvert.SerializeObject(tweet);
        byte[] dataAsBytes = Encoding.UTF8.GetBytes(dataAsJson);

       //Send to Kinesis

    }

Complete Exception:

System.NotImplementedException: The method or operation is not implemented. at Tweetinvi.Logic.JsonConverters.JsonPropertyConverterRepository.WriteJson(JsonWriter writer, Object value, JsonSerializer serializer) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable(JsonWriter writer, JsonConverter converter, Object value, JsonContract contract, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonConvert.SerializeObjectInternalA first chance exception of type 'System.NotImplementedException' occurred in TwitterIngestion.exe (Object value, Type type, JsonSerializer jsonSerializer) at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.SerializeObject(Object value) at TwitterIngestion.IngestionService.SendToKinesis(ITweet tweet) in c:\Users\sepehr500\Desktop\Work Stuff\TwitterIngestion\TwitterIngestion\IngestionTask.cs:line 104

1
For us to be of any help, we would need to know more. Can you include the complete ToString() output of the exception, including the traceback from JsonConvert.SerializeObject()?dbc
What "method or operation is not implemented"? If you surround the call to JsonConvert with a try { } catch (Exception ex) { Debug.WriteLine(ex); throw; } you can see the complete exception.dbc
It may be that TweetInvi does not support serialization. Many of its classes, e.g. TweetDTO use the attribute [JsonConverter(typeof(JsonPropertyConverterRepository))], and this class does not implement writing (always throws an exception).dbc
Can you download the source, modify JsonPropertyConverterRepository and add public override bool CanWrite { get { return false; } }, then build and use the local version? I'm not familiar with this library so I don't know if this is possible.dbc

1 Answers

-1
votes

Try following code:

private void SendToKinesis(ITweet tweet)
{


    var dataAsJson = JsonConvert.SerializeObject<ITweet>(tweet);
    byte[] dataAsBytes = Encoding.UTF8.GetBytes(dataAsJson);

   //Send to Kinesis

}