1

I'm using reflection to deserialize object from binary stream ("objType=SM.Backend.Entities.Erp.CodeListBase"):

var methodInfo = typeof(SM.Core.Serializator).GetMethod("DeserializeCache");
var genericMethod = methodInfo.MakeGenericMethod(objType);
var _objItem = genericMethod.Invoke(null, new[] { _streamedData });

It works. If I inspect _objItem in Locals window it looks like:_objItem

Now i would like to export _objItem content to json string:

var jsonString=JsonConvert.SerializeObject(_objItem, Formatting.Indented);

But result is empty: "[]". If I do the same for other objects it works. I guess for this object it doesn't work because it is complex type(nested):

SM.Backend.Entities.Erp.CodeListBase{SM.Backend.Entities.Erp.CodeList<SM.Backend.Entities.Erp.MaterialType>}.

Any idea how to extract the content from locals to json string? Should I convert object to different type first?

If I change _objItem to be iList of items of type:

SM.Backend.Entities.Erp.CodeList<SM.Backend.Entities.Erp.MaterialType>        
SM.Backend.Entities.Erp.CodeList<SM.Backend.Entities.Erp.ProductDescriptionType>

...

as you can see here: _objItem

the result is the same "[]". But collection is not empty.

9
  • SerializeObject((SM.Backend.Entities.Erp.CodeList<SM.Backend.Entities.Erp.MaterialType>)_objItem, Formatting.Indented); could be some problem with type identification. Commented Dec 21, 2016 at 10:57
  • By default, NewtonSoft.Json will only serialize public members stackoverflow.com/questions/29003215/… Commented Dec 21, 2016 at 11:01
  • Thanks. i think all members are public. And idea? Commented Dec 21, 2016 at 12:02
  • SM.Backend.Entities.Erp.CodeList<SM.Backend‌​.Entities.Erp.Materi‌​alType> _objItem = genericMethod.Invoke(null, new[] { _streamedData }); //try cast object to correct type or look at my first comment Commented Dec 21, 2016 at 12:15
  • But something work fine because "[]" it mean that it detect IEnumerable otherway you will get "{}" Commented Dec 21, 2016 at 12:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.