# StackOverflowException when accessing object properties

**URL:** <https://www.ruby-forum.com/t/stackoverflowexception-when-accessing-object-properties/153347>\
**Category:** IronRuby\
**Created:** [November 15, 2008, 7:33am UTC](https://www.ruby-forum.com/t/stackoverflowexception-when-accessing-object-properties/153347 "2008-11-15T07:33:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bvanderveen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed655f/32.png) [@bvanderveen](https://www.ruby-forum.com/u/bvanderveen)\
**Post date:** [November 15, 2008, 7:33am UTC](https://www.ruby-forum.com/t/stackoverflowexception-when-accessing-object-properties/153347/1 "2008-11-15T07:33:43Z")

</div>

Hello all,

Why does the stack overflow?

class Program  
{  
static void Main(string[] args)  
{  
ScriptRuntime runtime = Ruby.CreateRuntime();  
ScriptEngine engine = runtime.GetRubyEngine();

```
    ScriptScope scope = engine.CreateScope();
    scope.SetVariable("my_var", new TestClass() { Text = "Hello

```

world!", Number = 42 });

```
    ScriptSource source =

```

engine.CreateScriptSourceFromString(“my\_var.text”);  
Console.WriteLine(source.Execute(scope));  
}  
}

class TestClass  
{  
public string Text;  
public int Number;  
}

If I set “my\_var” to a string and query it’s Length property, no  
problem. I’m sure I’m missing somethingâ€”I came up with this code by  
reading a PDF found on the IronRuby site  
([http://ironruby.net/@api/deki/files/1/=dlr-spec-hosting.pdf](http://ironruby.net/@api/deki/files/1/=dlr-spec-hosting.pdf) –  
redirects to Amazon S3) because I couldn’t find any examples. Maybe I  
need to somehow import TestClass’ namespace into the scope?

Thanks a lot, and apologies in advance for formatting problems (can’t  
find a preview post option).

benjamin

---

<div class="post-metadata">

**Author:** ![bvanderveen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed655f/32.png) [@bvanderveen](https://www.ruby-forum.com/u/bvanderveen)\
**Post date:** [November 15, 2008, 8:07am UTC](https://www.ruby-forum.com/t/stackoverflowexception-when-accessing-object-properties/153347/2 "2008-11-15T08:07:45Z")

</div>

I think this is because you need to reference the IronRuby.Libraries  
dll.  
Strange error I know.

On Sat, Nov 15, 2008 at 7:33 PM, Benjamin Van der veen  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![bvanderveen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed655f/32.png) [@bvanderveen](https://www.ruby-forum.com/u/bvanderveen)\
**Post date:** [November 15, 2008, 11:15pm UTC](https://www.ruby-forum.com/t/stackoverflowexception-when-accessing-object-properties/153347/3 "2008-11-15T23:15:57Z")

</div>

Hello Andrew,

Andrew P. wrote:

> I think this is because you need to reference the IronRuby.Libraries  
> dll.  
> Strange error I know.
> 
> On Sat, Nov 15, 2008 at 7:33 PM, Benjamin Van der veen  
> \<removed\_email\_address@domain.invalid

Ah, yes, this fixed the stack overflow error. Strange indeedâ€”thanks for  
the tip! However, it’s still not properly resolving the property  
correctly:

MissingMethodException: undefined method `text’ for  
#My::Namespace::TestClass:0x000005c

I tried changing TestClass’ fields to properties so that they would get  
compiled as methods:

class TestClass  
{  
public string Text { get; set; }  
public int Number { get; set; }  
}

but no dice. Also tried capitalizing “Text”. Still works with  
String.Length though (whether I reference it as “my\_var.length” or  
“my\_var.Length”. Any ideas?

(Also, as somewhat of a side-note, is there a different syntax for  
accessing field on CLR objects in IronRuby? Is this possible or must  
they be properties?)

Thanks again,  
benjamin

---

<div class="post-metadata">

**Author:** ![bvanderveen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed655f/32.png) [@bvanderveen](https://www.ruby-forum.com/u/bvanderveen)\
**Post date:** [November 16, 2008, 2:12am UTC](https://www.ruby-forum.com/t/stackoverflowexception-when-accessing-object-properties/153347/4 "2008-11-16T02:12:34Z")

</div>

Tomas M. wrote:

> Isn’t the class internal? (We should improve error reporting related to  
> visibility)  
> Try to make it public. Public fields should be accessible in the same  
> way properties are.
> 
> Tomas

Yep, that was the problem. Declared it public and it works now.

Thanks,  
benjamin

---

<div class="post-metadata">

**Author:** ![bvanderveen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed655f/32.png) [@bvanderveen](https://www.ruby-forum.com/u/bvanderveen)\
**Post date:** [November 16, 2008, 1:08am UTC](https://www.ruby-forum.com/t/stackoverflowexception-when-accessing-object-properties/153347/5 "2008-11-16T01:08:37Z")

</div>

Isn’t the class internal? (We should improve error reporting related to  
visibility)  
Try to make it public. Public fields should be accessible in the same  
way properties are.

Tomas
