[Ironruby-core] Can't create instances

Ivan Porto Carrero ivan at flanders.co.nz
Sun Jul 26 10:55:52 EDT 2009


More surprises followed :).
Because if now one of the inheriting ruby classes defines an
initialize method then it is mapped to the initialize method of the C#
base class. This
initialize method of my controller is totally different from the
initialize method of the parent controller in C# it wouldn't be an override. Is
there a way to tell IronRuby it shouldn't walk up the chain except when
called super and to disregard the C# implemented method?  I tried using
alias_method but that didn't help.


public abstract class ControllerBase {
   public virtual void Initialize(RequestContext context){
      // do stuff here
   }
}

/* More Subclasses in C# go here none override Initialize */

class Controller < System::Web::Mvc::IronRuby::Controllers::RubyController
         # An attempt to put the base method out of play
alias_method :base_controller_initialize, :initialize

        # This approach had different problems
# undef_method :initialize


def initialize; end
 end

class ApplicationController < Controller

  def initialize(user_svc=nil)
    @user_service = user_svc||UserService.new(uow_scope)
  end

end

In the ApplicationController it now says that the first argument is of type
RequestContext which isn't what there is supposed to be there. It should be
a UserService

In this case the initialize method is not that extremely important because
it was there to make unit testing easier. I can set the dependencies some
other way. At this point I'm more curious about how it works or will work in
the future, CLR interop has been very interesting so far :)

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)



On Sun, Jul 26, 2009 at 10:34 AM, Ivan Porto Carrero <ivan at flanders.co.nz>wrote:

> Thanks that did it.
> The System.Web.Mvc.Controller class does have an initialize method with 1
> param.
> ---
> Met vriendelijke groeten - Best regards - Salutations
> Ivan Porto Carrero
> Blog: http://flanders.co.nz
> Twitter: http://twitter.com/casualjim
> Author of IronRuby in Action (http://manning.com/carrero)
>
>
>
> On Sun, Jul 26, 2009 at 2:38 AM, Tomas Matousek <
> Tomas.Matousek at microsoft.com> wrote:
>
>> If you want an immediate fix go to RubyClass.cs and add && initializer is RubyLibraryMethodInfo
>> to the condition on line 1213:
>>
>>
>>
>> bool hasLibraryInitializer = !hasRubyInitializer &&
>> initializer.DeclaringModule != Context.ObjectClass && initializer is
>> RubyLibraryMethodInfo;
>>
>>
>>
>> That should do the trick.
>>
>>
>>
>> Tomas
>>
>>
>>
>> *From:* ironruby-core-bounces at rubyforge.org [mailto:
>> ironruby-core-bounces at rubyforge.org] *On Behalf Of *Tomas Matousek
>> *Sent:* Saturday, July 25, 2009 5:16 PM
>>
>> *To:* ironruby-core at rubyforge.org
>> *Subject:* Re: [Ironruby-core] Can't create instances
>>
>>
>>
>> Does any of the C# subclasses have Initialize method? That might be the
>> problem. I’ll fix it asap.
>>
>>
>>
>> Tomas
>>
>>
>>
>> *From:* ironruby-core-bounces at rubyforge.org [mailto:
>> ironruby-core-bounces at rubyforge.org] *On Behalf Of *Ivan Porto Carrero
>> *Sent:* Saturday, July 25, 2009 4:45 PM
>> *To:* ironruby-core at rubyforge.org
>> *Subject:* Re: [Ironruby-core] Can't create instances
>>
>>
>>
>> It's a subclass of RubyController (
>> http://github.com/casualjim/ironrubymvc/blob/f9b28881187865dcff3389231e627ee2c4f93d14/IronRubyMvc/Controllers/RubyController.cs
>> )
>>
>>
>>
>> There are no constructors defined in any of the class definitions.
>>
>>
>>
>> HomeController.rb:
>>
>>
>> http://github.com/casualjim/ironrubymvc/blob/f9b28881187865dcff3389231e627ee2c4f93d14/IronRubyMvcWeb/Controllers/HomeController.rb
>>
>>
>>
>> Ruby controller base class:
>>
>>
>> http://github.com/casualjim/ironrubymvc/blob/f9b28881187865dcff3389231e627ee2c4f93d14/IronRubyMvc/Controllers/controller.rb#L360
>>
>>
>>
>> RubyController:
>>
>>
>> http://github.com/casualjim/ironrubymvc/blob/f9b28881187865dcff3389231e627ee2c4f93d14/IronRubyMvc/Controllers/RubyController.cs
>> ---
>> Met vriendelijke groeten - Best regards - Salutations
>> Ivan Porto Carrero
>> Blog: http://flanders.co.nz
>> Twitter: http://twitter.com/casualjim
>> Author of IronRuby in Action (http://manning.com/carrero)
>>
>> On Sun, Jul 26, 2009 at 1:30 AM, Tomas Matousek <
>> Tomas.Matousek at microsoft.com> wrote:
>>
>> What is the class being created that fails?
>>
>>
>>
>> Tomas
>>
>>
>>
>> *From:* ironruby-core-bounces at rubyforge.org [mailto:
>> ironruby-core-bounces at rubyforge.org] *On Behalf Of *Ivan Porto Carrero
>> *Sent:* Saturday, July 25, 2009 4:01 PM
>> *To:* ironruby-core
>> *Subject:* [Ironruby-core] Can't create instances
>>
>>
>>
>> Hi
>>
>>
>>
>> I just updated from github and ironrubymvc broke.
>>
>>
>>
>> This method would happily execute before the update.
>>
>>
>>
>> public object CreateInstance(RubyClass rubyClass)
>>
>>         {
>>
>>             return Operations.CreateInstance(rubyClass);
>>
>>         }
>>
>>
>>
>> Now it throws an exception. Do I need to change something?
>>
>>
>>
>>
>>
>> ArgumentException: wrong number of arguments (0 for 1)]
>>
>>    Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame frame) +58
>>
>>    Microsoft.Scripting.Interpreter.Interpreter.RunInstructions(InterpretedFrame frame) +90
>>
>>    Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) +104
>>
>>    Microsoft.Scripting.Interpreter.LightLambda.Run2(T0 arg0, T1 arg1) +337
>>
>>    IronRuby.Runtime.Calls.InterpretedFuncDispatcher`2.Invoke(CallSite callSite, T0 arg0) +574
>>
>>    System.Dynamic.UpdateDelegates.UpdateAndExecute1(CallSite site, T0 arg0) +1217
>>
>>    CallSite.Target(Closure , CallSite , Object ) +414
>>
>>    System.Dynamic.UpdateDelegates.UpdateAndExecute1(CallSite site, T0 arg0) +1217
>>
>>    Microsoft.Scripting.Runtime.DynamicOperations.CreateInstance(Object obj, Object[] parameters) +209
>>
>>    Microsoft.Scripting.Hosting.ObjectOperations.CreateInstance(Object obj, Object[] parameters) +51
>>
>>    System.Web.Mvc.IronRuby.Core.RubyEngine.CreateInstance(RubyClass rubyClass) in C:\dev\ironrubymvc\IronRubyMvc\Core\RubyEngine.cs:100
>>
>>    System.Web.Mvc.IronRuby.Controllers.RubyControllerFactory.ConfigureController(RubyClass rubyClass, RequestContext requestContext) in C:\dev\ironrubymvc\IronRubyMvc\Controllers\RubyControllerFactory.cs:87
>>
>>    System.Web.Mvc.IronRuby.Controllers.RubyControllerFactory.LoadController(RequestContext requestContext, String controllerName) in C:\dev\ironrubymvc\IronRubyMvc\Controllers\RubyControllerFactory.cs:73
>>
>>    System.Web.Mvc.IronRuby.Controllers.RubyControllerFactory.CreateController(RequestContext requestContext, String controllerName) in C:\dev\ironrubymvc\IronRubyMvc\Controllers\RubyControllerFactory.cs:40
>>
>>    System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +128
>>
>>    System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +57
>>
>>    System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
>>
>>    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
>>
>>    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
>>
>> ---
>> Met vriendelijke groeten - Best regards - Salutations
>> Ivan Porto Carrero
>> Blog: http://flanders.co.nz
>> Twitter: http://twitter.com/casualjim
>> Author of IronRuby in Action (http://manning.com/carrero)
>>
>>
>> _______________________________________________
>> Ironruby-core mailing list
>> Ironruby-core at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/ironruby-core
>>
>>
>>
>> _______________________________________________
>> Ironruby-core mailing list
>> Ironruby-core at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/ironruby-core
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090726/1fc25de8/attachment.html>


More information about the Ironruby-core mailing list