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.
602cf5e435d48bb762e8a1a7bf7424a6?d=identicon&s=25 Aaron Feng (Guest)
on 2008-12-05 22: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.
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2008-12-05 22: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: ironruby-core-bounces@rubyforge.org
[mailto:ironruby-core-bounces@rubyforge.org] On Behalf Of Aaron Feng
Sent: Friday, December 05, 2008 1:07 PM
To: ironruby-core@rubyforge.org
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.
68f1bd9e9a7d9d10f0278c6535f700fe?d=identicon&s=25 Michael Letterle (Guest)
on 2008-12-05 22: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 Matousek
<Tomas.Matousek@microsoft.com
602cf5e435d48bb762e8a1a7bf7424a6?d=identicon&s=25 Aaron Feng (Guest)
on 2008-12-05 23: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
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2008-12-05 23: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: ironruby-core-bounces@rubyforge.org
[mailto:ironruby-core-bounces@rubyforge.org] On Behalf Of Michael
Letterle
Sent: Friday, December 05, 2008 1:58 PM
To: ironruby-core@rubyforge.org
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 Matousek
<Tomas.Matousek@microsoft.com<mailto:Tomas.Matousek@microsoft.com>>
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:
ironruby-core-bounces@rubyforge.org<mailto:ironruby-core-bounces@rubyforge.org>
[mailto:ironruby-core-bounces@rubyforge.org<mailto:ironruby-core-bounces@rubyforge.org>]
On Behalf Of Aaron Feng
Sent: Friday, December 05, 2008 1:07 PM
To: ironruby-core@rubyforge.org<mailto:ironruby-core@rubyforge.org>
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.
602cf5e435d48bb762e8a1a7bf7424a6?d=identicon&s=25 Aaron Feng (Guest)
on 2008-12-08 17: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
1e39a948a58f4569c53d971c2e120920?d=identicon&s=25 Ivan Porto carrero (casualjim)
on 2008-12-08 18: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>
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2008-12-08 20: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: ironruby-core-bounces@rubyforge.org
[mailto:ironruby-core-bounces@rubyforge.org] On Behalf Of Ivan Porto
Carrero
Sent: Monday, December 08, 2008 9:46 AM
To: ironruby-core@rubyforge.org
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 Feng
<aaron.feng@gmail.com<mailto:aaron.feng@gmail.com>> 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
Ironruby-core@rubyforge.org<mailto:Ironruby-core@rubyforge.org>
http://rubyforge.org/mailman/listinfo/ironruby-core
1e39a948a58f4569c53d971c2e120920?d=identicon&s=25 Ivan Porto carrero (casualjim)
on 2008-12-08 20:24
(Received via mailing list)
Yes that works


On Mon, Dec 8, 2008 at 8:11 PM, Tomas Matousek
<Tomas.Matousek@microsoft.com
602cf5e435d48bb762e8a1a7bf7424a6?d=identicon&s=25 Aaron Feng (Guest)
on 2008-12-08 21: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 Matousek
<Tomas.Matousek@microsoft.com
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2008-12-08 21:46
(Received via mailing list)
You can use Assembly.LoadFile and point it to an absolute path instead.

Tomas

From: ironruby-core-bounces@rubyforge.org
[mailto:ironruby-core-bounces@rubyforge.org] On Behalf Of Aaron Feng
Sent: Monday, December 08, 2008 12:33 PM
To: ironruby-core@rubyforge.org
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 Matousek
<Tomas.Matousek@microsoft.com<mailto:Tomas.Matousek@microsoft.com>>
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:
ironruby-core-bounces@rubyforge.org<mailto:ironruby-core-bounces@rubyforge.org>
[mailto:ironruby-core-bounces@rubyforge.org<mailto:ironruby-core-bounces@rubyforge.org>]
On Behalf Of Ivan Porto Carrero
Sent: Monday, December 08, 2008 9:46 AM

To: ironruby-core@rubyforge.org<mailto:ironruby-core@rubyforge.org>
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 Feng
<aaron.feng@gmail.com<mailto:aaron.feng@gmail.com>> 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
Ironruby-core@rubyforge.org<mailto:Ironruby-core@rubyforge.org>
http://rubyforge.org/mailman/listinfo/ironruby-core
7f064c6157df91df3efc93bdd6687fe2?d=identicon&s=25 Dudu Baião (Guest)
on 2008-12-08 22:42
(Received via mailing list)
Hi Aaron!

I'm doing this way for now:

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

?

2008/12/8 Aaron Feng <aaron.feng@gmail.com>:
602cf5e435d48bb762e8a1a7bf7424a6?d=identicon&s=25 Aaron Feng (Guest)
on 2008-12-08 22: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 Matousek
<Tomas.Matousek@microsoft.com
1e39a948a58f4569c53d971c2e120920?d=identicon&s=25 Ivan Porto carrero (casualjim)
on 2008-12-08 22: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)
602cf5e435d48bb762e8a1a7bf7424a6?d=identicon&s=25 Aaron Feng (Guest)
on 2008-12-08 22: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
2560112a578efab82a5fddd7284ef4f2?d=identicon&s=25 Brad Wilson (Guest)
on 2008-12-09 00: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.