Handling C# lower case namespaces


#1

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:

I also noticed that “puts” does not output the value of Int64. However,
it
does if I use Console.WriteLine in my ruby program.


#2

Just monkey-patch it:

class System::Int64

 def inspect
      self.to_string.to_s
 end

end

:wink:

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


#3

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/ViewFeedback.aspx?FeedbackID=298408

I also noticed that “puts” does not output the value of Int64. However,
it does if I use Console.WriteLine in my ruby program.


#4

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


#5

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


#6

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


#7

Thumbs up :slight_smile:

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

:wink:

On Fri, Dec 5, 2008 at 4:50 PM, Tomas M.
<removed_email_address@domain.invalidmailto: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.invalidmailto:removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalidmailto:removed_email_address@domain.invalid]
On Behalf Of Aaron F.
Sent: Friday, December 05, 2008 1:07 PM
To: removed_email_address@domain.invalidmailto: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/ViewFeedback.aspx?FeedbackID=298408

I also noticed that “puts” does not output the value of Int64. However,
it does if I use Console.WriteLine in my ruby program.


#8

Yes that works

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


#9

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.0http://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.invalidmailto: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.0http://1.0.0.0, Culture=neutral, PublicKeyToken=null”)

Do I have any other options?

Thanks,

Aaron


Ironruby-core mailing list
removed_email_address@domain.invalidmailto:removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core


#10

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.invalidmailto: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.0http://1.0.0.0, Culture=neutral,
PublicKeyToken=null”).GetType(‘IronNails.View.XamlProxy’)

Tomas

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

To: removed_email_address@domain.invalidmailto: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.0http://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.invalidmailto: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.0http://1.0.0.0, Culture=neutral, PublicKeyToken=null”)

Do I have any other options?

Thanks,

Aaron


Ironruby-core mailing list
removed_email_address@domain.invalidmailto:removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core


#11

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:


#12

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


#13

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


#14

Normally
foo = x::y::z::Foo.new(1)

in the console you need to use global variables:$foo =
x::y::z::Foo.new(1)


#15

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/


#16

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