# RubyDotNet r4 and namespaces

**URL:** <https://rubytalk.org/t/rubydotnet-r4-and-namespaces/8277>\
**Category:** ruby-talk\
**Created:** [27 September 2003 03:49 UTC](https://rubytalk.org/t/rubydotnet-r4-and-namespaces/8277 "2003-09-27T03:49:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_R\_Pierce](https://avatars.discourse-cdn.com/v4/letter/j/8edcca/32.png) [@John\_R\_Pierce](https://rubytalk.org/u/John_R_Pierce)\
**Post date:** [27 September 2003 03:49 UTC](https://rubytalk.org/t/rubydotnet-r4-and-namespaces/8277/1 "2003-09-27T03:49:20Z")

</div>

> I grabbed the r4 release of RubyDotNet from  
> [http://www.saltypickle.com/rubydotnet](http://www.saltypickle.com/rubydotnet), and it works great (well, on my  
> laptop. My main PC seems to have issues with multiple versions of the  
> .net framework installed).

Very interesting…both of us (the developers) are running our machines with  
both version of .NET (1.0 and 1.1) as we develop this product. Can you provide  
us specific errors you are getting?

> I had no trouble writing my own C# class and calling it from Ruby  
> (pretty sweet). But I if put my class in a namespace I can’t get the  
> Ruby code to find it. I get errors about an unknown constant (i.e., the  
> namespace for the C# class).

Are you building your custom C# class under .NET 1.1? Are you referencing the  
dll using a fully qualified path including extension? If so to both of these,  
can you provide a copy of your class either on this mailing list or directly to  
me (if it is too big). I’d like to see this.

We actually have this exact scenario in a test case included in the  
distribution. If you look in the Ruby\tests folder you will find a test file  
called “TestCoreBridge.rb”. Inside this file there are several test cases with  
respect to the class “TestClasses.NumberHolder”. I’d be curious if this test  
passes on your machine. To run the tests you must be in a command prompt that  
has csc.exe in the path as the test will compile a custom c# class and then  
access it.

> On a side note, is there a connection between RubyDotNet at  
> [saltypickle.com](http://saltypickle.com), and the rubydotnet at [rubydotnet.sourceforge.net](http://rubydotnet.sourceforge.net), other  
> the (confusing) use of essentially the same name?

Gosh, what were we thinking? Guess we need a namespace to resolve conflicts.  
Anyways, [www.saltypickle.com](http://www.saltypickle.com) is the home the Ruby/.NET bridge. We also run a  
site on [rubyforge.org](http://rubyforge.org) called rubydotnet. SourceForge already had a rubydotnet  
project – and we didn’t know it until too late. Guess this explanation is still  
confusing – oh well.

Regards,

John

> **···**
>
> On Sat, 27 Sep 2003 10:44:00 +0900, James Britt wrote:

---

<div class="post-metadata">

**Author:** ![James\_Britt7](https://avatars.discourse-cdn.com/v4/letter/j/eada6e/32.png) [@James\_Britt7](https://rubytalk.org/u/James_Britt7)\
**Post date:** [27 September 2003 05:38 UTC](https://rubytalk.org/t/rubydotnet-r4-and-namespaces/8277/2 "2003-09-27T05:38:26Z")

</div>

John R. Pierce wrote:

> > I grabbed the r4 release of RubyDotNet from  
> > [http://www.saltypickle.com/rubydotnet](http://www.saltypickle.com/rubydotnet), and it works great (well, on my  
> > laptop. My main PC seems to have issues with multiple versions of the  
> > .net framework installed).
> 
> Very interesting…both of us (the developers) are running our machines with  
> both version of .NET (1.0 and 1.1) as we develop this product. Can you provide  
> us specific errors you are getting?

If I run Learninga.rb, I get a WIndows message box, titled Microsof  
Visual C++ Runtime Library, with the message

```
Runtime Error!

Program c:\ruby\bin\ruby.exe

R6029
 -This program cannot run using the active version of the Microsoft 

```

.NET runtime  
Please contact that application’s support team for more information.

I’m thinking I have path or registry issues here, and may try to remove  
earlier installations and simply use 1.1. (I’ve had annoying  
experiences getting the framework installed, so I’m not convinced paths  
and registry entries are entirely correct.)

> > I had no trouble writing my own C# class and calling it from Ruby  
> > (pretty sweet). But I if put my class in a namespace I can’t get the  
> > Ruby code to find it. I get errors about an unknown constant (i.e., the  
> > namespace for the C# class).
> 
> Are you building your custom C# class under .NET 1.1? Are you referencing the  
> dll using a fully qualified path including extension? If so to both of these,  
> can you provide a copy of your class either on this mailing list or directly to  
> me (if it is too big). I’d like to see this.

Yes to both. csc.exe tells me:  
C:\>csc  
Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4  
for Microsoft (R) .NET Framework version 1.1.4322  
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

(Curiously, I see now that I have assorted earlier version on the laptop  
as well. Not sure that matters, or they’re of any value.)

Here’s the class:

using System;  
using Neurogami;  
using BlogtariDotNet;

namespace Neurogami {  
class Utils{  
public static void db( string msg ) {  
Console.WriteLine( "[DBUG] " + msg );  
}  
}  
}  
// namespace BlogtariDotNet {  
class BlogtariSample {  
static void Main( string args ) {  
try {  
DateTime today = DateTime.Now;  
Console.WriteLine( “The time is " + today.ToString() ) ;  
BlogtariSample bs = new BlogtariSample();  
Utils.db( bs.parse( “Foobar” ) );  
}  
catch ( Exception exception ) {  
Console.WriteLine( exception.Message );  
}  
}  
public string parse( string s ) {  
return s + " ”;  
}  
}  
// }

Anyway, so long as the BlogtariDotNet namespace is left commented, and  
my Ruby code just calls BlogtariSample.new() directly, all is good.  
But trying to use the name space and calling  
BlogtariDotNet.BlogtariSample.new() fails.

Thanks, and thanks for the outstanding code.

James Britt

> **···**
>
> > On Sat, 27 Sep 2003 10:44:00 +0900, James Britt wrote:

---

<div class="post-metadata">

**Author:** ![Wayne\_Vucenic2](https://avatars.discourse-cdn.com/v4/letter/w/e9a140/32.png) [@Wayne\_Vucenic2](https://rubytalk.org/u/Wayne_Vucenic2)\
**Post date:** [28 September 2003 05:08 UTC](https://rubytalk.org/t/rubydotnet-r4-and-namespaces/8277/3 "2003-09-28T05:08:42Z")

</div>

I just heard about RubyDotNet, and it looks really great!

I did encounter a problem while trying to use drag and drop. (RubyDotNet  
r4, Ruby 1.8, .NET 1.1, Windows XP). Here's a stripped down piece of  
code that demonstrates the problem:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;require 'dotnet'

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loadLibrary 'System.Windows.Forms'

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;form = Form.new  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;form.topMost = true  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;form.text = 'Drag and Drop Test'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;form.AllowDrop = true;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Application.Run form

When I run this I get a "Microsoft .NET Framework" dialog saying "An  
unhandled exception has occurred in your application...DragDrop  
registration failed" with the following details:

\*\*\*\*\*\*\*\*\*\*\*\*\*\* Exception Text \*\*\*\*\*\*\*\*\*\*\*\*\*\*  
System.InvalidOperationException: DragDrop registration failed. ---\>  
System.Threading.ThreadStateException: The current thread must set to  
Single Thread Apartment (STA) mode before OLE calls can be made.  
Ensure that your Main function has STAThreadAttribute marked on it.  
at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept)  
--- End of inner exception stack trace ---  
at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept)  
at System.Windows.Forms.Control.OnHandleCreated(EventArgs e)  
at System.Windows.Forms.Form.OnHandleCreated(EventArgs e)  
at System.Windows.Forms.Control.WmCreate(Message& m)  
at System.Windows.Forms.Control.WndProc(Message& m)  
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)  
at System.Windows.Forms.ContainerControl.WndProc(Message& m)  
at System.Windows.Forms.Form.WmCreate(Message& m)  
at System.Windows.Forms.Form.WndProc(Message& m)  
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)  
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)  
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,  
IntPtr wparam, IntPtr lparam)

Thanks!!!

Wayne  
No Bugs Software  
"Ruby and C++ Contract Programming in Silicon Valley"

---

<div class="post-metadata">

**Author:** ![Thomas\_Sondergaard](https://avatars.discourse-cdn.com/v4/letter/t/ecae2f/32.png) [@Thomas\_Sondergaard](https://rubytalk.org/u/Thomas_Sondergaard)\
**Post date:** [28 September 2003 10:31 UTC](https://rubytalk.org/t/rubydotnet-r4-and-namespaces/8277/4 "2003-09-28T10:31:42Z")

</div>

Apparently there is a need to set the COM ApartmentState to STA

Adding this in the first line of the ruby Init\_dotnet function makes it go  
away:

System::Threading:🧵:CurrentThread-\>ApartmentState =  
System::Threading::ApartmentState::STA;

Cheers,

Thomas

“Wayne Vucenic” [wvucenic@netgate.net](mailto:wvucenic@netgate.net) wrote in message  
[news:182202853037.20030927220828@netgate.net](mailto:news:182202853037.20030927220828@netgate.net)…

> **···**
>
> > I just heard about RubyDotNet, and it looks really great!
> > 
> > I did encounter a problem while trying to use drag and drop. (RubyDotNet  
> > r4, Ruby 1.8, .NET 1.1, Windows XP). Here’s a stripped down piece of  
> > code that demonstrates the problem:
> > 
> > ```
> > require 'dotnet'
> > 
> > loadLibrary 'System.Windows.Forms'
> > 
> > form = Form.new
> > form.topMost = true
> > form.text = 'Drag and Drop Test'
> > form.AllowDrop = true;
> > 
> > Application.Run form
> > 
> > ```
> > 
> > When I run this I get a “Microsoft .NET Framework” dialog saying “An  
> > unhandled exception has occurred in your application…DragDrop  
> > registration failed” with the following details:
> > 
> > \*\*\*\*\*\*\*\*\*\*\*\*\*\* Exception Text \*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> > System.InvalidOperationException: DragDrop registration failed. —\>  
> > System.Threading.ThreadStateException: The current thread must set to  
> > Single Thread Apartment (STA) mode before OLE calls can be made.  
> > Ensure that your Main function has STAThreadAttribute marked on it.  
> > at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept)  
> > — End of inner exception stack trace —  
> > at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept)  
> > at System.Windows.Forms.Control.OnHandleCreated(EventArgs e)  
> > at System.Windows.Forms.Form.OnHandleCreated(EventArgs e)  
> > at System.Windows.Forms.Control.WmCreate(Message& m)  
> > at System.Windows.Forms.Control.WndProc(Message& m)  
> > at System.Windows.Forms.ScrollableControl.WndProc(Message& m)  
> > at System.Windows.Forms.ContainerControl.WndProc(Message& m)  
> > at System.Windows.Forms.Form.WmCreate(Message& m)  
> > at System.Windows.Forms.Form.WndProc(Message& m)  
> > at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)  
> > at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)  
> > at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,  
> > IntPtr wparam, IntPtr lparam)
> > 
> > Thanks!!!
> > 
> > Wayne  
> > No Bugs Software  
> > “Ruby and C++ Contract Programming in Silicon Valley”

---

<div class="post-metadata">

**Author:** ![Thomas\_Sondergaard](https://avatars.discourse-cdn.com/v4/letter/t/ecae2f/32.png) [@Thomas\_Sondergaard](https://rubytalk.org/u/Thomas_Sondergaard)\
**Post date:** [28 September 2003 11:11 UTC](https://rubytalk.org/t/rubydotnet-r4-and-namespaces/8277/5 "2003-09-28T11:11:48Z")

</div>

I was a little fast there. It seems to be sufficient to do it from ruby:

System::Threading::CurrentThread.ApartmentState =  
System::Threading::ApartmentState.STA

or with the module you are using, I would guess:

CurrentThread.ApartmentState = ApartmentState.STA

Try it out.

Cheers,

Tom

“Thomas Sondergaard” [thomas@FirstNameGoesHereSondergaard.com](mailto:thomas@FirstNameGoesHereSondergaard.com) wrote in  
message news:3f76b756$0$48887$edfadb0f@dtext02.news.tele.dk…

> Apparently there is a need to set the COM ApartmentState to STA
> 
> Adding this in the first line of the ruby Init\_dotnet function makes it go  
> away:
> 
> System::Threading:🧵:CurrentThread-\>ApartmentState =  
> System::Threading::ApartmentState::STA;
> 
> Cheers,
> 
> Thomas
> 
> “Wayne Vucenic” [wvucenic@netgate.net](mailto:wvucenic@netgate.net) wrote in message  
> [news:182202853037.20030927220828@netgate.net](mailto:news:182202853037.20030927220828@netgate.net)…
> 
> > I just heard about RubyDotNet, and it looks really great!
> > 
> > I did encounter a problem while trying to use drag and drop.  
> > (RubyDotNet

> **···**
>
> > > r4, Ruby 1.8, .NET 1.1, Windows XP). Here’s a stripped down piece of  
> > > code that demonstrates the problem:
> > > 
> > > ```
> > > require 'dotnet'
> > > 
> > > loadLibrary 'System.Windows.Forms'
> > > 
> > > form = Form.new
> > > form.topMost = true
> > > form.text = 'Drag and Drop Test'
> > > form.AllowDrop = true;
> > > 
> > > Application.Run form
> > > 
> > > ```
> > > 
> > > When I run this I get a “Microsoft .NET Framework” dialog saying “An  
> > > unhandled exception has occurred in your application…DragDrop  
> > > registration failed” with the following details:
> > > 
> > > \*\*\*\*\*\*\*\*\*\*\*\*\*\* Exception Text \*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> > > System.InvalidOperationException: DragDrop registration failed. —\>  
> > > System.Threading.ThreadStateException: The current thread must set to  
> > > Single Thread Apartment (STA) mode before OLE calls can be made.  
> > > Ensure that your Main function has STAThreadAttribute marked on it.  
> > > at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept)  
> > > — End of inner exception stack trace —  
> > > at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept)  
> > > at System.Windows.Forms.Control.OnHandleCreated(EventArgs e)  
> > > at System.Windows.Forms.Form.OnHandleCreated(EventArgs e)  
> > > at System.Windows.Forms.Control.WmCreate(Message& m)  
> > > at System.Windows.Forms.Control.WndProc(Message& m)  
> > > at System.Windows.Forms.ScrollableControl.WndProc(Message& m)  
> > > at System.Windows.Forms.ContainerControl.WndProc(Message& m)  
> > > at System.Windows.Forms.Form.WmCreate(Message& m)  
> > > at System.Windows.Forms.Form.WndProc(Message& m)  
> > > at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)  
> > > at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)  
> > > at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,  
> > > IntPtr wparam, IntPtr lparam)
> > > 
> > > Thanks!!!
> > > 
> > > Wayne  
> > > No Bugs Software  
> > > “Ruby and C++ Contract Programming in Silicon Valley”

---

<div class="post-metadata">

**Author:** ![Wayne\_Vucenic2](https://avatars.discourse-cdn.com/v4/letter/w/e9a140/32.png) [@Wayne\_Vucenic2](https://rubytalk.org/u/Wayne_Vucenic2)\
**Post date:** [28 September 2003 21:01 UTC](https://rubytalk.org/t/rubydotnet-r4-and-namespaces/8277/6 "2003-09-28T21:01:16Z")

</div>

Hi Tom and John,

Thank you both for your helpful replies. I really appreciate it!

I tried doing it from Ruby, but I still got exactly the same error.  
The only reason I could think of that this wouldn’t work would be if  
this thread had already entered the MTA. I checked, and this was the  
case. For example, the simple program

```
require 'dotnet'
puts System.Threading.Thread.CurrentThread.ApartmentState.ToString

```

outputs “MTA”

So, I’ll use your earlier suggestion.

Thanks again,

Wayne

Sunday, September 28, 2003, 4:11:48 AM, you wrote:

> **···**
>
> > I was a little fast there. It seems to be sufficient to do it from ruby:
> 
> > System::Threading::CurrentThread.ApartmentState =  
> > System::Threading::ApartmentState.STA
> 
> > or with the module you are using, I would guess:
> 
> > CurrentThread.ApartmentState = ApartmentState.STA

---

<div class="post-metadata">

**Author:** ![Zach\_Dennis1](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@Zach\_Dennis1](https://rubytalk.org/u/Zach_Dennis1)\
**Post date:** [28 September 2003 21:35 UTC](https://rubytalk.org/t/rubydotnet-r4-and-namespaces/8277/7 "2003-09-28T21:35:23Z")

</div>

Hey All,

I’m attempting to use a Cygwin setup for Apache and mod\_ruby…(or eruby),  
but I can’t get them to work. mod\_ruby won’t ‘make’. It tosses an error  
about the mod\_ruby.o file and quits. I have tried with 1.0.7 and 1.1.0 and i  
can’t get it to go.

Here’s what I’m doing.

./configure.rb --with-apxs=/usr/local/apache2/bin/apxs //this part works!!  
make //errors out

the last few lines of the ‘make’ running are:

> **···**
>
> * * *
> 
> ## request.o(.text+0x3824:/tmp/mod\_ruby-1.0.7.request.c:1652: undefined reference to '\_apr\_table\_setn’ collect2: ld returned 1 exit status make: \*\*\* [mod\_ruby.so] Error 1
> 
> And that’s it!! Any ideas?
> 
> TIA
> 
> -Z
