Question

I have a c# class "Document" with overloaded constructors (int id), (guid id) and some more parameter options - and no overload with 0 parameters. When I try to create a new object with IronRuby I stumble. It says it wants to have 0 arguments, so:

d = Document.new

works fine. But when I try

d = Document.new some_integer

I get the error message

"wrong number of arguments (1 for 0)"

The class def looks like this:

public Document(int id) : base(id)
{
  // some code
}

Edit: here's the complete code. It's in an Umbraco context, and I translate namespaces with lower caseing to be able to use them in IronRuby:

$LOAD_PATH << "C:\\inetpub-dev\\dev.mysite.com\\bin"
require "cms.dll"
require "businesslogic.dll"

Web = Object.const_get("umbraco").const_get("cms").const_get("businesslogic").const_get("web")
existing_document_id = 1065
existing_document = Web::Document.new(existing_document_id)

Same code in C#:

var existingDocument = new umbraco.cms.businesslogic.web.Document(1065);
Was it helpful?

Solution

I wonder if you are hitting a namespace collision somewhere.
Is there any possibility that Document is defined somewhere else in what you are including?

We can't see what your base class looks like
Also, we can't see what requires/includes you are using

I set up an example, and it seems to work as expected:

namespace IRConstructorParamSpike
{
    public abstract class BaseDocument
    {
        public BaseDocument(int id) { }
    }

    public class Document : BaseDocument
    {
        public Document(int id) : base(id) { }
    }

    public class SomeDocument : BaseDocument
    {
        public SomeDocument(int id) : base(id) { }
    }
}

Here is what the session looked like (using IronRuby 1.1.4.0):

require 'IRConstructorParamSpike.dll' => true

d = Document.new (ir):1:in `const_missing': uninitialized constant Object::Document (NameError) from (ir):1 <-- Because I didn't include the namespace

d = IRConstructorParamSpike::Document.new (ir):1: wrong number of arguments (0 for 1) (ArgumentError) <-- What we would expect with no parameterless constructor

d = IRConstructorParamSpike::Document.new 10 => IRConstructorParamSpike.Document

Could you try with this simpler example code and see if you can create the objects in the way you are expecting?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top