# R169 problem

**URL:** <https://www.ruby-forum.com/t/r169-problem/152542>\
**Category:** IronRuby\
**Created:** [November 5, 2008, 12:09am UTC](https://www.ruby-forum.com/t/r169-problem/152542 "2008-11-05T00:09:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [November 5, 2008, 12:09am UTC](https://www.ruby-forum.com/t/r169-problem/152542/1 "2008-11-05T00:09:27Z")

</div>

Hi,

After trying out 169, all my previously passing tests are now failing  
with:

failed: System.InvalidCastException : Unable to cast object of type  
‘IronRuby.Runtime.RubyTopLevelScope’ to type  
‘IronRuby.Runtime.RubyContext’.  
C:\Dev\ironruby\trunk\src\ironruby\Runtime\Calls\CallArguments.cs(111,0):  
at IronRuby.Runtime.Calls.CallArguments.get\_RubyContext()  
C:\Dev\ironruby\trunk\src\ironruby\Runtime\Calls\MetaObjectBuilder.cs(137,0):  
at  
IronRuby.Runtime.Calls.MetaObjectBuilder.AddTargetTypeTest(CallArguments  
args)  
C:\Dev\ironruby\trunk\src\ironruby\Runtime\Calls\RubyCallAction.cs(108,0):  
at IronRuby.Runtime.Calls.RubyCallAction.Bind(MetaObjectBuilder  
metaBuilder, String methodName, CallArguments args)  
C:\Dev\ironruby\trunk\src\ironruby\Runtime\Calls\RubyCallAction.cs(102,0):  
at IronRuby.Runtime.Calls.RubyCallAction.Bind(MetaObject context,  
MetaObject[] args)  
C:\Dev\ironruby\trunk\src\Microsoft.Scripting.Core\Actions\MetaObjectBinder.cs(61,0):  
at System.Dynamic.Binders.MetaObjectBinder.Bind(Object[] args,  
ReadOnlyCollection`1 parameters, LabelTarget returnLabel) C:\Dev\ironruby\trunk\src\Microsoft.Scripting.Core\Actions\CallSiteOps.cs(53,0): at System.Runtime.CompilerServices.CallSiteOps.CreateNewRule[T](CallSite`1  
site, CallSiteRule`1 oldRule, CallSiteRule`1 originalRule, Object[]  
args)  
C:\Dev\ironruby\trunk\src\Microsoft.Scripting.Core\Actions\UpdateDelegates.Generated.cs(428,0):  
at  
System.Dynamic.Binders.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite  
site, T0 arg0, T1 arg1, T2 arg2)  
at IronRuby.Classes.Template$1.CoreRender(TextWriter )  
C:\Dev\nhaml\trunk\src\NHaml\Template.cs(18,0): at  
NHaml.Template.Render(TextWriter textWriter)  
at IronRuby.Classes.Template$1.Render(TextWriter )  
at _stub_$17##17(Closure , CallSite , Object , Object )  
C:\Dev\ironruby\trunk\src\Microsoft.Scripting.Core\Actions\UpdateDelegates.Generated.cs(299,0):  
at  
System.Dynamic.Binders.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite  
site, T0 arg0, T1 arg1)  
C:\Dev\ironruby\trunk\src\Microsoft.Scripting\Runtime\DynamicOperations.cs(83,0):  
at Microsoft.Scripting.Runtime.DynamicOperations.Invoke(Object obj,  
Object[] parameters)  
C:\Dev\ironruby\trunk\src\Microsoft.Scripting\Hosting\ObjectOperations.cs(76,0):  
at Microsoft.Scripting.Hosting.ObjectOperations.Call(Object obj,  
Object[] parameters)  
C:\Dev\nhaml\trunk\src\NHaml.Compilers.IronRuby\IronRubyTemplateFactory.cs(58,0):  
at  
NHaml.Compilers.IronRuby.IronRubyTemplateFactory.DlrShimTemplate.Render(TextWriter  
textWriter)

I’m roughly using the DLR like so:

scriptEngine = Ruby.CreateEngine();  
scriptEngine.Execute(templateSource);  
renderAction = \_scriptEngine.CreateScriptSourceFromString(className +  
“.new.method(:render)”).Execute();  
scriptEngine.Operations.Call(renderAction, textWriter);

– templateSource –

require ‘C:\Dev\nhaml\trunk\src\Tests\bin\Debug\NHaml.dll’  
require  
‘C:\Windows\assembly\GAC\_MSIL\System\2.0.0.0\_\_b77a5c561934e089\System.dll’  
class Templates\_IronRuby\_Welcome\_haml\<NHaml::Template  
def \_\_a(as)  
as.collect { |k,v|  
next unless v  
“#{k.to\_s.gsub(‘\_’,‘-’)}="#{v}"”  
}.compact.join(’ ‘)  
end  
def CoreRender(text\_writer)  
title = “Welcome to my [ASP.NET](http://ASP.NET) MVC Application using NHaml!”  
text\_writer.Write(’\<h2’)  
text\_writer.WriteLine(‘\>’)  
text\_writer.Write(’ ‘)  
text\_writer.WriteLine(title)  
text\_writer.WriteLine(’‘)  
text\_writer.Write(’\<p’)  
text\_writer.WriteLine(‘\>’)  
text\_writer.Write(’ ‘)  
text\_writer.WriteLine(“Yeah Baby!”)  
text\_writer.WriteLine(’

')  
end;end

– NHaml::Template –

public abstract class Template  
{  
private readonly OutputWriter \_outputWriter = new OutputWriter();

public virtual void Render(TextWriter textWriter)  
{  
Invariant.ArgumentNotNull(textWriter, “textWriter”);

```
_outputWriter.TextWriter = textWriter;

PreRender(_outputWriter);
CoreRender(textWriter);

```

}

protected virtual void PreRender(OutputWriter outputWriter)  
{  
}

protected abstract void CoreRender(TextWriter textWriter);

protected OutputWriter Output  
{  
get { return \_outputWriter; }  
}  
}

Any help appreciated.

Cheers,

Andrew.

---

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [November 18, 2008, 7:38am UTC](https://www.ruby-forum.com/t/r169-problem/152542/2 "2008-11-18T07:38:50Z")

</div>

Update: This is still broken on 172 except I had to change:

def CoreRender(text\_writer)

to:

def core\_render(text\_writer)

first.

Cheers,

Andrew.

---

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [November 18, 2008, 11:06am UTC](https://www.ruby-forum.com/t/r169-problem/152542/3 "2008-11-18T11:06:50Z")

</div>

I just committed a fix for interop to our internal repository. It  
should be merged out shortly.

---

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [November 19, 2008, 12:42am UTC](https://www.ruby-forum.com/t/r169-problem/152542/4 "2008-11-19T00:42:17Z")

</div>

It works now, cheers.
