# Trying to call interface method for a C# class

**URL:** <https://www.ruby-forum.com/t/trying-to-call-interface-method-for-a-c-class/207239>\
**Category:** IronRuby\
**Created:** [May 21, 2011, 4:30am UTC](https://www.ruby-forum.com/t/trying-to-call-interface-method-for-a-c-class/207239 "2011-05-21T04:30:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [May 21, 2011, 4:30am UTC](https://www.ruby-forum.com/t/trying-to-call-interface-method-for-a-c-class/207239/1 "2011-05-21T04:30:57Z")

</div>

I am attempting to call an interface method for a .net class and am  
having difficulty. I’m using IronRuby v1.1.2 and working with  
ScintillaNet, a .net wrapper for the Scintilla control.

A portion of the ScintillaNet::Scintilla class is below:

namespace ScintillaNet  
{  
…  
public partial class Scintilla : Control, INativeScintilla,  
ISupportInitialize  
{  
…  
}  
}

And a portion of the ScintillaNet::INativeScintilla interface is below:

namespace ScintillaNet  
{  
public interface INativeScintilla  
{  
…  
void BackTab();  
…  
}  
}

I came across another forum discussion  
[http://rubyforge.org/pipermail/ironruby-core/2009-January/003520.html](http://rubyforge.org/pipermail/ironruby-core/2009-January/003520.html),  
which seems to fall along the lines of what I’m trying to do, but I’m  
not sure the features discussed there are implemented yet.

I’ve reduced the troublesome code to a relatively short length to play  
with alternative approaches:

require “bin/ScintillaNet”  
class ScintillaNet::Scintilla  
include ScintillaNet::INativeScintilla

```
def self.ztest2()
  z = ScintillaNet::Scintilla.new()
  puts "z[#{z}]"
  #; z.BackTab() # undefined method `BackTab' for

```

ScintillaNet.Scintilla:ScintillaNet::Scintilla (NoMethodError)  
#; ScintillaNet::INativeScintilla(z).BackTab() # undefined method  
`INativeScintilla' for ScintillaNet:Module (NoMethodError) #; ScintillaNet::INativeScintilla.BackTab() # undefined method `BackTab’ for ScintillaNet::INativeScintilla:Module (NoMethodError)  
puts “fence”  
end  
end

ScintillaNet::Scintilla.ztest2()  
puts “done”

The three approaches above yield the errors to the right of each line.

Thanks in advance for any assistance you might be able to provide.  
–John

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [May 21, 2011, 9:14pm UTC](https://www.ruby-forum.com/t/trying-to-call-interface-method-for-a-c-class/207239/2 "2011-05-21T21:14:05Z")

</div>

On Fri, May 20, 2011 at 10:30 PM, John Cawley III [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I am attempting to call an interface method for a .net class and am  
> having difficulty. I’m using IronRuby v1.1.2 and working with  
> ScintillaNet, a .net wrapper for the Scintilla control.

John, I’m a little unclear about the problem you’re trying to solve  
… I’ve got some questions inline:

> A portion of the ScintillaNet::Scintilla class is below:
> 
> namespace ScintillaNet  
> {  
> …  
> public partial class Scintilla : Control, INativeScintilla,  
> ISupportInitialize  
> {  
> …

Is BackTab implemented in any other partial C# class of Scintilla? If  
not, than you should be getting a compiler error …

> void BackTab();  
> …  
> }  
> }
> 
> I came across another forum discussion  
> [http://rubyforge.org/pipermail/ironruby-core/2009-January/003520.html](http://rubyforge.org/pipermail/ironruby-core/2009-January/003520.html),  
> which seems to fall along the lines of what I’m trying to do, but I’m  
> not sure the features discussed there are implemented yet.

That thread is about calling _explicit_ interface methods, which we do  
now support, though the API needs some work:  
[http://ironruby.codeplex.com/workitem/1594](http://ironruby.codeplex.com/workitem/1594).

> I’ve reduced the troublesome code to a relatively short length to play  
> with alternative approaches:
> 
> require “bin/ScintillaNet”  
> class ScintillaNet::Scintilla  
> include ScintillaNet::INativeScintilla

How come your including this interface here? In C# this class already  
implements INativeScintilla …

> def self.ztest2()  
> z = ScintillaNet::Scintilla.new()  
> puts “z[#{z}]”  
> #; z.BackTab() # undefined method `BackTab’ for  
> ScintillaNet.Scintilla:ScintillaNet::Scintilla (NoMethodError)

This works if I implement BackTab in this class, but again not sure if  
that’s what you’re trying to do…

> #; ScintillaNet::INativeScintilla(z).BackTab() # undefined method  
> `INativeScintilla’ for ScintillaNet:Module (NoMethodError)

This is invalid IronRuby; .NET interfaces are exposed to IronRuby as  
ruby modules, and here you’re using a module as a method.

> #; ScintillaNet::INativeScintilla.BackTab() # undefined method  
> `BackTab’ for ScintillaNet::INativeScintilla:Module (NoMethodError)

Also invalid as INativeScintilla is basically a module without any  
actual methods implemented on it, as a .NET interface doesn’t have  
method implementations.

> –John  
> Let me know if you can clear those things up …

~Jimmy

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [May 22, 2011, 3:24pm UTC](https://www.ruby-forum.com/t/trying-to-call-interface-method-for-a-c-class/207239/3 "2011-05-22T15:24:38Z")

</div>

And that does it! Thank you, Jimmy!

Summarizing: I was trying to use the ScintillaNet control from IronRuby.  
The main class in the ScintillaNet DLL is ScintillaNet::Scintilla, and  
I’d been able to invoke its methods and work with its properties from  
IronRuby just fine. That class also implements the INativeScintilla  
interface, but I was having difficulty working with the methods and  
properties of that interface from IronRuby. Accessing those was the  
goal.

From .net, you should be able to access those with code like this:

((INativeScintilla)scintilla).BackTab()

The equivelent in IronRuby (thanks to your reference to Work Item 1594,  
[http://ironruby.codeplex.com/workitem/1594](http://ironruby.codeplex.com/workitem/1594)) is:

scintilla.clr\_member( ScintillaNet::INativeScintilla, :BackTab ).call

That was the mechanism I was reaching around for.

Thanks again,  
–John

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [May 22, 2011, 11:36pm UTC](https://www.ruby-forum.com/t/trying-to-call-interface-method-for-a-c-class/207239/4 "2011-05-22T23:36:00Z")

</div>

I’m hoping to do some work to fix some of the bugs in IronRuby’s visual  
studio integration, but I’m having a few issues getting a dev  
environment  
up and running.

- I can build IronStudio.sln from the Solutions folder, and my modified  
version of the IronRuby tools loads in the visual studio experimental  
instance and is fine.
- I can build the full IronRuby installer, and when I install it, my  
modified version of IronRuby tools loads in the normal visual studio  
instance.

But, I can’t figure out how I can build a modified version of IronRuby  
tools and run it in a normal instance without doing the full MSI release  
build.  
Simply building the tools and then launching a normal visual studio  
instance produces this error message when I open any solution:

* * *

## Microsoft Visual Studio

The ‘Microsoft.IronRubyTools.IronRubyToolsPackage, IronRubyTools,  
Version=1.0.0.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1’  
package  
did not load correctly.

The problem may have been caused by a configuration change or by the  
installation of another extension. You can get more information by  
running  
the application together with the /log parameter on the command line,  
and  
then examining the file  
‘C:\Users\orione\AppData\Roaming\Microsoft\VisualStudio\10.0\ActivityLog.xml’.

## Continue to show this error message?

## Yes No

If I click Yes, then the projects load, but this dialog reappears  
whenever  
I launch VS or load any solutions. If I click no, VS disables the  
IronRuby  
addin, and I have to run devenv /ResetSkipPkgs to put it back (and then  
the error messages come back). The only way to “fix” the issue is to  
uninstall/reinstall the IronRuby tools MSI itself.

Is there a way to get the non-experimental instance of visual studio to  
load IronRuby tools without having to do a full build if the MSI in  
release mode?

Thanks, Orion

###########################################################################  
This e-mail is confidential and may contain information subject to legal  
privilege. If you are not the intended recipient please advise us of  
our  
error by return e-mail then delete this e-mail and any attached files.  
You may not copy, disclose or use the contents in any way.

The views expressed in this e-mail may not be those of Gallagher Group  
Ltd or subsidiary companies thereof.  
###########################################################################
