# Stupid to\_clr\_string

**URL:** <https://www.ruby-forum.com/t/stupid-to-clr-string/145977>\
**Category:** IronRuby\
**Created:** [August 15, 2008, 6:27pm UTC](https://www.ruby-forum.com/t/stupid-to-clr-string/145977 "2008-08-15T18:27:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_CSHess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@Sean\_CSHess](https://www.ruby-forum.com/u/Sean_CSHess)\
**Post date:** [August 15, 2008, 6:27pm UTC](https://www.ruby-forum.com/t/stupid-to-clr-string/145977/1 "2008-08-15T18:27:38Z")

</div>

Ok, I keep running into this over and over. Whenever Silverlight passes  
a  
string to javascript, it comes out as some unreadable object. You have  
to  
call to\_clr\_string to get it working.  
This is ok… You can monkey patch some of the javascript library code  
to  
fix it, but with HtmlPage.window.invoke, for example, it’s not easy to  
do  
because it sends a variable number of arguments.

Is this being fixed? Or is this something we’re going to have to deal  
with  
for a while?

Thanks  
~sean

---

<div class="post-metadata">

**Author:** ![Sean\_CSHess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@Sean\_CSHess](https://www.ruby-forum.com/u/Sean_CSHess)\
**Post date:** [August 15, 2008, 6:41pm UTC](https://www.ruby-forum.com/t/stupid-to-clr-string/145977/2 "2008-08-15T18:41:06Z")

</div>

Ah, makes sense. I’m totally unfamiliar with the way IronRuby is  
implemented. Is it possible to switch it to a clr string any time it  
calls  
any framework code? (like the invoke function I’m using).  
~sean

---

<div class="post-metadata">

**Author:** ![Sean\_CSHess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@Sean\_CSHess](https://www.ruby-forum.com/u/Sean_CSHess)\
**Post date:** [August 15, 2008, 6:35pm UTC](https://www.ruby-forum.com/t/stupid-to-clr-string/145977/3 "2008-08-15T18:35:50Z")

</div>

This isn’t a Silverlight issue but an IronRuby one. A Ruby string  
simply isn’t the same as a CLR string - the Ruby string is mutable while  
the CLR string is not.

We need to come up with a cohesive plan for dealing with the difference  
before we can “fix” anything.

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Sean C.  
Hess  
Sent: Friday, August 15, 2008 9:25 AM  
To: removed\_email\_address@domain.invalid  
Subject: [Ironruby-core] Stupid to\_clr\_string

Ok, I keep running into this over and over. Whenever Silverlight passes  
a string to javascript, it comes out as some unreadable object. You  
have to call to\_clr\_string to get it working.

This is ok… You can monkey patch some of the javascript library code  
to fix it, but with HtmlPage.window.invoke, for example, it’s not easy  
to do because it sends a variable number of arguments.

Is this being fixed? Or is this something we’re going to have to deal  
with for a while?

Thanks  
~sean

---

<div class="post-metadata">

**Author:** ![Sean\_CSHess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@Sean\_CSHess](https://www.ruby-forum.com/u/Sean_CSHess)\
**Post date:** [August 15, 2008, 6:46pm UTC](https://www.ruby-forum.com/t/stupid-to-clr-string/145977/4 "2008-08-15T18:46:57Z")

</div>

The binder could automatically create a conversion - in effect, calling  
to\_clr\_string for you automatically. But it might be a little strange  
for the binder to do that automatically in one direction and not the  
other - which is why I said that there needs to be a plan before we make  
any changes.

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Sean C.  
Hess  
Sent: Friday, August 15, 2008 9:39 AM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Stupid to\_clr\_string

Ah, makes sense. I’m totally unfamiliar with the way IronRuby is  
implemented. Is it possible to switch it to a clr string any time it  
calls any framework code? (like the invoke function I’m using).

~sean  
On Fri, Aug 15, 2008 at 10:33 AM, Curt H.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

This isn’t a Silverlight issue but an IronRuby one. A Ruby string  
simply isn’t the same as a CLR string - the Ruby string is mutable while  
the CLR string is not.

We need to come up with a cohesive plan for dealing with the difference  
before we can “fix” anything.

From:  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
On Behalf Of Sean C. Hess  
Sent: Friday, August 15, 2008 9:25 AM  
To: removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: [Ironruby-core] Stupid to\_clr\_string

Ok, I keep running into this over and over. Whenever Silverlight passes  
a string to javascript, it comes out as some unreadable object. You  
have to call to\_clr\_string to get it working.

This is ok… You can monkey patch some of the javascript library code  
to fix it, but with HtmlPage.window.invoke, for example, it’s not easy  
to do because it sends a variable number of arguments.

Is this being fixed? Or is this something we’re going to have to deal  
with for a while?

Thanks

~sean

---

<div class="post-metadata">

**Author:** ![Sean\_CSHess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@Sean\_CSHess](https://www.ruby-forum.com/u/Sean_CSHess)\
**Post date:** [August 15, 2008, 6:48pm UTC](https://www.ruby-forum.com/t/stupid-to-clr-string/145977/5 "2008-08-15T18:48:43Z")

</div>

…oh, if the CLR interface we’re calling is typed to System.Object  
instead of System.String, then we probably can’t do any kind of  
automatic conversion.

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Sean C.  
Hess  
Sent: Friday, August 15, 2008 9:39 AM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Stupid to\_clr\_string

Ah, makes sense. I’m totally unfamiliar with the way IronRuby is  
implemented. Is it possible to switch it to a clr string any time it  
calls any framework code? (like the invoke function I’m using).

~sean  
On Fri, Aug 15, 2008 at 10:33 AM, Curt H.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

This isn’t a Silverlight issue but an IronRuby one. A Ruby string  
simply isn’t the same as a CLR string - the Ruby string is mutable while  
the CLR string is not.

We need to come up with a cohesive plan for dealing with the difference  
before we can “fix” anything.

From:  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
On Behalf Of Sean C. Hess  
Sent: Friday, August 15, 2008 9:25 AM  
To: removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: [Ironruby-core] Stupid to\_clr\_string

Ok, I keep running into this over and over. Whenever Silverlight passes  
a string to javascript, it comes out as some unreadable object. You  
have to call to\_clr\_string to get it working.

This is ok… You can monkey patch some of the javascript library code  
to fix it, but with HtmlPage.window.invoke, for example, it’s not easy  
to do because it sends a variable number of arguments.

Is this being fixed? Or is this something we’re going to have to deal  
with for a while?

Thanks

~sean

---

<div class="post-metadata">

**Author:** ![Sean\_CSHess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@Sean\_CSHess](https://www.ruby-forum.com/u/Sean_CSHess)\
**Post date:** [August 15, 2008, 6:50pm UTC](https://www.ruby-forum.com/t/stupid-to-clr-string/145977/6 "2008-08-15T18:50:28Z")

</div>

Makes sense.

---

<div class="post-metadata">

**Author:** ![Sean\_CSHess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@Sean\_CSHess](https://www.ruby-forum.com/u/Sean_CSHess)\
**Post date:** [August 15, 2008, 11:09pm UTC](https://www.ruby-forum.com/t/stupid-to-clr-string/145977/7 "2008-08-15T23:09:24Z")

</div>

You can monkey-patch the Silverlight classes you’re using to do the  
to\_clr\_string for you. For example HtmlDocument#GetElementById requires  
you pass it a ClrString, which can be annoying from IronRuby. So, you  
can make it take a Ruby string or symbol like this:

module System::Windows::Browser  
class HtmlDocument  
alias\_method orig\_get\_element\_by\_id, get\_element\_by\_id  
def get\_element\_by\_id(id)  
orig\_get\_element\_by\_id(id.to\_s.to\_clr\_string)  
end  
end  
end

# usage

include System::Windows:Browser  
element = HtmlPage.document.get\_element\_by\_id(:foo)

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Sean C.  
Hess  
Sent: Friday, August 15, 2008 9:48 AM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Stupid to\_clr\_string

Makes sense.  
On Fri, Aug 15, 2008 at 10:44 AM, Curt H.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

The binder could automatically create a conversion - in effect, calling  
to\_clr\_string for you automatically. But it might be a little strange  
for the binder to do that automatically in one direction and not the  
other - which is why I said that there needs to be a plan before we make  
any changes.

From:  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
On Behalf Of Sean C. Hess  
Sent: Friday, August 15, 2008 9:39 AM

To: removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: [Ironruby-core] Stupid to\_clr\_string

Ah, makes sense. I’m totally unfamiliar with the way IronRuby is  
implemented. Is it possible to switch it to a clr string any time it  
calls any framework code? (like the invoke function I’m using).

~sean

On Fri, Aug 15, 2008 at 10:33 AM, Curt H.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

This isn’t a Silverlight issue but an IronRuby one. A Ruby string  
simply isn’t the same as a CLR string - the Ruby string is mutable while  
the CLR string is not.

We need to come up with a cohesive plan for dealing with the difference  
before we can “fix” anything.

From:  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
On Behalf Of Sean C. Hess  
Sent: Friday, August 15, 2008 9:25 AM  
To: removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: [Ironruby-core] Stupid to\_clr\_string

Ok, I keep running into this over and over. Whenever Silverlight passes  
a string to javascript, it comes out as some unreadable object. You  
have to call to\_clr\_string to get it working.

This is ok… You can monkey patch some of the javascript library code  
to fix it, but with HtmlPage.window.invoke, for example, it’s not easy  
to do because it sends a variable number of arguments.

Is this being fixed? Or is this something we’re going to have to deal  
with for a while?

Thanks

~sean

* * *

Ironruby-core mailing list  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)
