Forum: IronRuby Handling C# lower case namespaces

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aaron F. (Guest)
on 2008-12-05 23:07
(Received via mailing list)
It seems like the current version does not handle lower case namespaces
when
referencing a .NET DLL.  It thinks it is a method call whenever a
constant
starts with lower case.  It also doesn't handle non-alphabet characters
such
as _ (underscore).

I'm trying to call WCF service from IronRuby via the proxies file.
svcutil
converts all namespaces in the proxies file to lower case.  Here's some
info
on it:

http://connect.microsoft.com/wcf/feedback/ViewFeed...

I also noticed that "puts" does not output the value of Int64.  However,
it
does if I use Console.WriteLine in my ruby program.
Tomas M. (Guest)
on 2008-12-05 23:50
(Received via mailing list)
Well, that's very unfortunate. They seems to break .NET guidelines for
namespace naming. It's not compatible with Ruby language to have
lowercased namespaces since they behave like modules. Module names must
start with an upper case. We can add some API to overcome this, but it
won't be pretty. Something like

clr.class_get :foo, :bar, :baz would return class for type foo.bar.baz.

For now you can use reflection API to get the type (and Ruby class for
that type):
System::Type.get_type("foo.bar.baz").to_class

As for Int64... it prints #<System::Int64:0x000005e>, which is not
particularly useful. It should probably call ToString. I'll file a bug.

Tomas

From: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] On Behalf Of Aaron F.
Sent: Friday, December 05, 2008 1:07 PM
To: removed_email_address@domain.invalid
Subject: [Ironruby-core] Handling C# lower case namespaces

It seems like the current version does not handle lower case namespaces
when referencing a .NET DLL.  It thinks it is a method call whenever a
constant starts with lower case.  It also doesn't handle non-alphabet
characters such as _ (underscore).

I'm trying to call WCF service from IronRuby via the proxies file.
svcutil converts all namespaces in the proxies file to lower case.
Here's some info on it:

http://connect.microsoft.com/wcf/feedback/ViewFeed...

I also noticed that "puts" does not output the value of Int64.  However,
it does if I use Console.WriteLine in my ruby program.
Michael L. (Guest)
on 2008-12-05 23:58
(Received via mailing list)
Just monkey-patch it:

class System::Int64

     def inspect
          self.to_string.to_s
     end
end

;)



On Fri, Dec 5, 2008 at 4:50 PM, Tomas M.
<removed_email_address@domain.invalid
Aaron F. (Guest)
on 2008-12-06 00:02
(Received via mailing list)
Tomas,

> System::Type.get_type("foo.bar.baz").to_class

Are you sure that works with lower case namespaces?  I tried it real
quick,
and didn't seem to work for me.  But I'll try it again later.

Aaron
Tomas M. (Guest)
on 2008-12-06 00:11
(Received via mailing list)
Thumbs up :)

You might however expect this to work for all CLR types. In which case
you can indeed monkey patch it as well (kind of):

>>> class Object
...   def to_s
...     self.class.name[0,8] == "System::" ? to_string.to_s : super
...   end
... end
=> nil
>>>
=> nil
>>> require 'mscorlib'
=> true
>>>
=> nil
>>> System::Convert.to_int64(1234)
=> 1234

Tomas

From: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] On Behalf Of Michael
Letterle
Sent: Friday, December 05, 2008 1:58 PM
To: removed_email_address@domain.invalid
Subject: Re: [Ironruby-core] Handling C# lower case namespaces

Just monkey-patch it:

class System::Int64

     def inspect
          self.to_string.to_s
     end
end

;)


On Fri, Dec 5, 2008 at 4:50 PM, Tomas M.
<removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>>
wrote:

Well, that's very unfortunate. They seems to break .NET guidelines for
namespace naming. It's not compatible with Ruby language to have
lowercased namespaces since they behave like modules. Module names must
start with an upper case. We can add some API to overcome this, but it
won't be pretty. Something like



clr.class_get :foo, :bar, :baz would return class for type foo.bar.baz.



For now you can use reflection API to get the type (and Ruby class for
that type):

System::Type.get_type("foo.bar.baz").to_class



As for Int64... it prints #<System::Int64:0x000005e>, which is not
particularly useful. It should probably call ToString. I'll file a bug.



Tomas



From:
removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>
[mailto:removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>]
On Behalf Of Aaron F.
Sent: Friday, December 05, 2008 1:07 PM
To: 
removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>
Subject: [Ironruby-core] Handling C# lower case namespaces



It seems like the current version does not handle lower case namespaces
when referencing a .NET DLL.  It thinks it is a method call whenever a
constant starts with lower case.  It also doesn't handle non-alphabet
characters such as _ (underscore).

I'm trying to call WCF service from IronRuby via the proxies file.
svcutil converts all namespaces in the proxies file to lower case.
Here's some info on it:

http://connect.microsoft.com/wcf/feedback/ViewFeed...

I also noticed that "puts" does not output the value of Int64.  However,
it does if I use Console.WriteLine in my ruby program.
Aaron F. (Guest)
on 2008-12-08 18:59
(Received via mailing list)
Tomas,

I tried it again.  I couldn't get the following to work with my own DLL
even
If I capitalize the namespace (It does work fine with build in types
like
System.String):

> System::Type.get_type("Abc.Hi, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null")

Do I have any other options?

Thanks,

Aaron
Ivan P. (Guest)
on 2008-12-08 19:47
(Received via mailing list)
I get the same behavior.
I can load types from the CLR but not from my own assembly.

I copied my assembly into the folder that contains ir.exe

>>> require 'mscorlib'
=> true
>>> require 'IronNails.Library, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'
=> true
>>> IronNails::View::XamlProxy
=> IronNails::View::XamlProxy
>>> System::Type.get_type 'IronNails.View.XamlProxy'
=> nil
>>> System::Type.get_type 'System.String'
=> #<System::RuntimeType:0x000005c>
>>> IronNails::View::XamlProxy.to_clr_type
=> #<System::RuntimeType:0x000005e>
Tomas M. (Guest)
on 2008-12-08 21:14
(Received via mailing list)
Can you load the assembly and get the type explicitly?

require ‘mscorlib’
System::Reflection::Assembly.Load(“IronNails.Library, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=null").GetType('IronNails.View.XamlProxy’)

Tomas

From: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] On Behalf Of Ivan Porto
Carrero
Sent: Monday, December 08, 2008 9:46 AM
To: removed_email_address@domain.invalid
Subject: Re: [Ironruby-core] Handling C# lower case namespaces

I get the same behavior.
I can load types from the CLR but not from my own assembly.

I copied my assembly into the folder that contains ir.exe

>>> require 'mscorlib'
=> true
>>> require 'IronNails.Library, Version=1.0.0.0<http://1.0.0.0>, Culture=neutral, 
PublicKeyToken=null'
=> true
>>> IronNails::View::XamlProxy
=> IronNails::View::XamlProxy
>>> System::Type.get_type 'IronNails.View.XamlProxy'
=> nil
>>> System::Type.get_type 'System.String'
=> #<System::RuntimeType:0x000005c>
>>> IronNails::View::XamlProxy.to_clr_type
=> #<System::RuntimeType:0x000005e>



On Mon, Dec 8, 2008 at 5:54 PM, Aaron F.
<removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>> 
wrote:
Tomas,

I tried it again.  I couldn't get the following to work with my own DLL
even If I capitalize the namespace (It does work fine with build in
types like System.String):

> System::Type.get_type("Abc.Hi, Version=1.0.0.0<http://1.0.0.0>, Culture=neutral, 
PublicKeyToken=null")

Do I have any other options?

Thanks,

Aaron

_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>
http://rubyforge.org/mailman/listinfo/ironruby-core
Ivan P. (Guest)
on 2008-12-08 21:24
(Received via mailing list)
Yes that works


On Mon, Dec 8, 2008 at 8:11 PM, Tomas M.
<removed_email_address@domain.invalid
Aaron F. (Guest)
on 2008-12-08 22:33
(Received via mailing list)
Ok,  I got Assembly.Load and Type.get_type both to work with my own DLL.
The actual DLL have to live where ir.exe lives.  Is there a way for it
to
look in the directory of the ruby file?  Like the way require statement
work.

Aaron



On Mon, Dec 8, 2008 at 2:11 PM, Tomas M.
<removed_email_address@domain.invalid
Tomas M. (Guest)
on 2008-12-08 22:46
(Received via mailing list)
You can use Assembly.LoadFile and point it to an absolute path instead.

Tomas

From: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] On Behalf Of Aaron F.
Sent: Monday, December 08, 2008 12:33 PM
To: removed_email_address@domain.invalid
Subject: Re: [Ironruby-core] Handling C# lower case namespaces

Ok,  I got Assembly.Load and Type.get_type both to work with my own DLL.
The actual DLL have to live where ir.exe lives.  Is there a way for it
to look in the directory of the ruby file?  Like the way require
statement work.

Aaron


On Mon, Dec 8, 2008 at 2:11 PM, Tomas M.
<removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>>
wrote:

Can you load the assembly and get the type explicitly?



require 'mscorlib'

System::Reflection::Assembly.Load("IronNails.Library,
Version=1.0.0.0<http://1.0.0.0>, Culture=neutral,
PublicKeyToken=null").GetType('IronNails.View.XamlProxy')



Tomas



From:
removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>
[mailto:removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>]
On Behalf Of Ivan Porto C.
Sent: Monday, December 08, 2008 9:46 AM

To: 
removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>
Subject: Re: [Ironruby-core] Handling C# lower case namespaces



I get the same behavior.
I can load types from the CLR but not from my own assembly.

I copied my assembly into the folder that contains ir.exe

>>> require 'mscorlib'
=> true
>>> require 'IronNails.Library, Version=1.0.0.0<http://1.0.0.0>, Culture=neutral, 
PublicKeyToken=null'
=> true
>>> IronNails::View::XamlProxy
=> IronNails::View::XamlProxy
>>> System::Type.get_type 'IronNails.View.XamlProxy'
=> nil
>>> System::Type.get_type 'System.String'
=> #<System::RuntimeType:0x000005c>
>>> IronNails::View::XamlProxy.to_clr_type
=> #<System::RuntimeType:0x000005e>



On Mon, Dec 8, 2008 at 5:54 PM, Aaron F.
<removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>> 
wrote:

Tomas,

I tried it again.  I couldn't get the following to work with my own DLL
even If I capitalize the namespace (It does work fine with build in
types like System.String):

> System::Type.get_type("Abc.Hi, Version=1.0.0.0<http://1.0.0.0>, Culture=neutral, 
PublicKeyToken=null")

Do I have any other options?

Thanks,

Aaron

_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>
http://rubyforge.org/mailman/listinfo/ironruby-core
Dudu Baião (Guest)
on 2008-12-08 23:42
(Received via mailing list)
Hi Aaron!

I'm doing this way for now:

require '../../your_folder/your_assembly.dll'

?

2008/12/8 Aaron F. <removed_email_address@domain.invalid>:
Aaron F. (Guest)
on 2008-12-08 23:45
(Received via mailing list)
I tried to load the struct the same way, but I don't know how to set the
value of it.  For example:

C#

namespace x.y.z {
    public struct Foo {
        public long Bar;
        public Foo(long bar) {
            this.Bar = bar;
        }
    }
}

var foo = new x.y.z.Foo(1);

IronRuby

Foo = Type.get_type("x.y.z.Foo, MyAssembly, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null", true).to_class

# how do I do the equivalent of
# var foo = new x.y.z.Foo(1); ?

Aaron


On Mon, Dec 8, 2008 at 3:45 PM, Tomas M.
<removed_email_address@domain.invalid
Ivan P. (Guest)
on 2008-12-08 23:52
(Received via mailing list)
Normally
foo = x::y::z::Foo.new(1)

in the console you need to use global variables:$foo =
x::y::z::Foo.new(1)
Aaron F. (Guest)
on 2008-12-08 23:58
(Received via mailing list)
Ivan,

In this case you actually can't do foo = x::y::z::Foo.new(1) because
IronRuby doesn't support lowercase namespace.  It think it's a method
call.

That's why I started out
Foo = Type.get_type("x.y.z.Foo, MyAssembly, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null", true).to_class

Aaron
Brad W. (Guest)
on 2008-12-09 01:02
(Received via mailing list)
Welcome to the "wonderful" world of Fusion.
If you use Assembly.LoadFrom, then you can only use the assembly
reference
itself to get the types. The canonical names don't match assemblies
loaded
using LoadFrom. To use Assembly.Load, it has to be in one of the
approved
search paths (which, by default, is the path of the launching executable
only, plus the GAC of course).

We went through an almost excruciating amount of pain with assembly load
paths and such to make all this work correctly in xUnit.net.

--
Brad    http://bradwilson.typepad.com/
This topic is locked and can not be replied to.