RubyDotNet r4 and namespaces

I grabbed the r4 release of RubyDotNet from
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, and the rubydotnet at 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 is the home the Ruby/.NET bridge. We also run a
site on 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:

John R. Pierce wrote:

I grabbed the r4 release of RubyDotNet from
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:

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"

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::thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;

Cheers,

Thomas

“Wayne Vucenic” wvucenic@netgate.net wrote in message
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”

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 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::thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;

Cheers,

Thomas

“Wayne Vucenic” wvucenic@netgate.net wrote in message
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”

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

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