# Bug in mscorlib, IronRuby, NewtonSoft.json..... or my code?

**URL:** <https://www.ruby-forum.com/t/bug-in-mscorlib-ironruby-newtonsoft-json-or-my-code/189550>\
**Category:** IronRuby\
**Created:** [June 3, 2010, 12:02am UTC](https://www.ruby-forum.com/t/bug-in-mscorlib-ironruby-newtonsoft-json-or-my-code/189550 "2010-06-03T00:02:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![benhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@benhiller](https://www.ruby-forum.com/u/benhiller)\
**Post date:** [June 3, 2010, 12:02am UTC](https://www.ruby-forum.com/t/bug-in-mscorlib-ironruby-newtonsoft-json-or-my-code/189550/1 "2010-06-03T00:02:31Z")

</div>

Hi,

I’m trying to use a third party library which has a dependency on  
NewtonSoft.json. I create a class within IronRuby and attempt to  
serialise the object to Json however it throws a null reference  
exception from within mscorlib.

Any ideas?? Example is below:

Thanks

Ben

class Company  
attr\_accessor :Name, :Id  
end

c = Company.new  
c.Name = ‘test’

require ‘Newtonsoft.Json’  
include Newtonsoft::Json  
JsonConvert.serialize\_object c

mscorlib:0:in `Equals': Object reference not set to an instance of an object. (System::NullReferenceException) from mscorlib:0:in`IndexOf’  
from mscorlib:0:in `IndexOf' from mscorlib:0:in`IndexOf’  
from Newtonsoft.Json:0:in `CheckForCircularReference' from Newtonsoft.Json:0:in`SerializeList’  
from Newtonsoft.Json:0:in `SerializeValue' from Newtonsoft.Json:0:in`SerializeISerializable’  
from Newtonsoft.Json:0:in `SerializeValue' from Newtonsoft.Json:0:in`SerializeISerializable’  
from Newtonsoft.Json:0:in `SerializeValue' from Newtonsoft.Json:0:in`WriteMemberInfoProperty’  
from Newtonsoft.Json:0:in `SerializeObject' from Newtonsoft.Json:0:in`SerializeValue’  
from Newtonsoft.Json:0:in `WriteMemberInfoProperty' from Newtonsoft.Json:0:in`SerializeObject’  
from Newtonsoft.Json:0:in `SerializeValue' from Newtonsoft.Json:0:in`SerializeISerializable’  
from Newtonsoft.Json:0:in `SerializeValue' from Newtonsoft.Json:0:in`Serialize’  
from Newtonsoft.Json:0:in `SerializeInternal' from Newtonsoft.Json:0:in`SerializeObject’  
from Newtonsoft.Json:0:in `SerializeObject’  
from (ir):1

---

<div class="post-metadata">

**Author:** ![benhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@benhiller](https://www.ruby-forum.com/u/benhiller)\
**Post date:** [June 3, 2010, 6:58am UTC](https://www.ruby-forum.com/t/bug-in-mscorlib-ironruby-newtonsoft-json-or-my-code/189550/2 "2010-06-03T06:58:08Z")

</div>

## make the class backed by a real .NET Type not a ruby type and the serializer will work again

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.

---

<div class="post-metadata">

**Author:** ![benhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@benhiller](https://www.ruby-forum.com/u/benhiller)\
**Post date:** [June 3, 2010, 11:03am UTC](https://www.ruby-forum.com/t/bug-in-mscorlib-ironruby-newtonsoft-json-or-my-code/189550/3 "2010-06-03T11:03:57Z")

</div>

I’m halfway through a library which serializes dynamic types to JSON. I  
guess that should work in this case; I’ll post when it’s done.

Cheers,  
Mark
