Defined?(xxx) behaves differently when called from Silverlight


#1

Hi,

I noticed something that I didn’t expect while working with Silverlight.

defined?(System::Windows::Forms::Control)

throws an exception:

MemberAccessException: uninitialized constant System::Windows::Forms
à IronRuby.Builtins.ModuleOps.ConstantMissing(RubyModule self, String
name)
à stub$2##1(Closure , CallSite , CodeContext , RubyModule , SymbolId
)
à System.Scripting.Actions.MatchCaller.Call3[T0,T1,T2,TRet](Func5 target, CallSite site, Object[] args) à System.Scripting.Actions.CallSite1.UpdateAndExecute(Object[] args)
à System.Scripting.Actions.UpdateDelegates.Update3[T,T0,T1,T2,TRet](CallSite
site, T0 arg0, T1 arg1, T2 arg2)
à IronRuby.Builtins.RubySites.ModuleConstMissing(CodeContext
context, RubyModule self, String name)

The same call under ir.exe will work as expected in MRI.

Can anyone else reproduce that issue (or is it something known
already), or is my silverlight install messing up ?

cheers,

– Thibaut


#2

Granted, it shouldn’t throw … and doesn’t for me in SL.

rb> defined?(System::Windows::Forms)
=> nil
rb> defined?(System::Windows::Forms::Controls)
=> nil


#3

On 4/1/09, Thibaut Barrère removed_email_address@domain.invalid wrote:

Can anyone else reproduce that issue (or is it something known
already), or is my silverlight install messing up ?

Well, there’s no System.Windows.Froms.Control in silverlight to begin
with.

defined?(System::Windows::Application)

does work though.


#4

System::Windows::Forms doesn’t exist in Silverlight. You want
System::Windows::Controls.


#5

On 4/2/09, Jb Evain removed_email_address@domain.invalid wrote:

defined?(System::Windows::Application)

does work though.

At least it works in the IronRuby repl. But trying to get a undefined
namespace doesn’t throw an exception either. How’re you running the
code?


#6

It seems to me that this misses the most important part of the original
report:

The same call under ir.exe will work as expected in MRI.

Presumably, System::Windows::Forms doesn’t exist in MRI, either :stuck_out_tongue:


#7

Hi,

I believe I need to give you more context about what I’m doing. In Magic
(see
herehttp://github.com/thbar/magic/blob/faf98c3161221e309290e7a6e311adb27fddf825/lib/magic.rb#L32
in
particular) I currently have a single file providing support for WPF,
Silverlight and Windows Forms. I use defined? to determine if one of
these
are available and adopt adequate behaviour.
So that’s why I run defined?(System::Windows::Forms::Control) inside
Silverlight. I can definitely think about alternatives (such as creating
a
specific file for each scenario) - I could do that but I’m trying to
stay
with a single file and avoid metaprogramming for the moment as it’s much
simpler to test.

So back to the issue, now that I hope you have a clearer understanding
of
what I’m doing here.

Using ruby 1.8.6 or ironruby v0.3, running this file through command
line
[ruby/ir] my_test.rb doesn’t choke:

raise “detected!” if defined?(System::Windows::Forms::Control)

Putting the same code as the first line of app.rb in a silverlight
ironruby
app fails:

MemberAccessException: uninitialized constant System::Windows::Forms

Is there any way to retrieve some accurate info on versioning from
inside
silverlight, so that I can make a better report or understand what’s
happening ?

– Thibaut


#8

The folder SL is installed into is the version; if you’re using SL2 it
should be C:\Program Files\Microsoft Silverlight\2.0.40115.0. SL3 Beta is
C:\Program Files\Microsoft Silverlight\3.0.40307.0.

I’m testing this from my Mac. I’ll be searching for the files using
find.

http://jimmy.schementi.com/silverlight/repro-defined.zip

Unzip that and double-click on the index.html file. The first line of
app.xap is defined?(System::Windows::Forms), and works fine. It also works
in the console. Let me know what happens for you.

Clicking on index.html shows a welcome message and the ironruby console,
so
it doesn’t seem to bang.

Editing has some weird behaviour: when I type (, defined? gets erased.
Maybe
totally unrelated, but this mean I can’t test in the console.

I’m a bit puzzled as why it fails. I’ll try to find some extra time to
investigate - may be related to the fact that I’m using Chiron on Mac ?

No idea what’s happening for the moment.

Thanks for the repro, Jimmy.

– Thibaut


#9

The folder SL is installed into is the version; if you’re using SL2 it
should be C:\Program Files\Microsoft Silverlight\2.0.40115.0. SL3 Beta
is C:\Program Files\Microsoft Silverlight\3.0.40307.0.

http://jimmy.schementi.com/silverlight/repro-defined.zip

Unzip that and double-click on the index.html file. The first line of
app.xap is defined?(System::Windows::Forms), and works fine. It also
works in the console. Let me know what happens for you.

~js

From: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] On Behalf Of Thibaut
Barrère
Sent: Thursday, April 02, 2009 2:57 AM
To: removed_email_address@domain.invalid
Subject: Re: [Ironruby-core] defined?(xxx) behaves differently when
called from Silverlight

Hi,

I believe I need to give you more context about what I’m doing. In Magic
(see
herehttp://github.com/thbar/magic/blob/faf98c3161221e309290e7a6e311adb27fddf825/lib/magic.rb#L32
in particular) I currently have a single file providing support for WPF,
Silverlight and Windows Forms. I use defined? to determine if one of
these are available and adopt adequate behaviour.

So that’s why I run defined?(System::Windows::Forms::Control) inside
Silverlight. I can definitely think about alternatives (such as creating
a specific file for each scenario) - I could do that but I’m trying to
stay with a single file and avoid metaprogramming for the moment as it’s
much simpler to test.

So back to the issue, now that I hope you have a clearer understanding
of what I’m doing here.

Using ruby 1.8.6 or ironruby v0.3, running this file through command
line [ruby/ir] my_test.rb doesn’t choke:

raise “detected!” if defined?(System::Windows::Forms::Control)

Putting the same code as the first line of app.rb in a silverlight
ironruby app fails:

MemberAccessException: uninitialized constant System::Windows::Forms

Is there any way to retrieve some accurate info on versioning from
inside silverlight, so that I can make a better report or understand
what’s happening ?

– Thibaut


#10

Ah, you were on a Mac. Let me know if it happens again.


#11

Hey,

I finally removed all the bits of Silverlight (/Library/Internet
Plug-Ins/Silverlight* , /Library/Receipts/Silverlight*.pkg) and
reinstalled SL2.

It now works as expected. I didn’t find some way to understand what
really happened, but the issue is solved anyway.

thanks for your support,

– Thibaut


#12

From: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] On Behalf Of Thibaut
Barrère
Sent: Thursday, April 02, 2009 3:44 PM
To: removed_email_address@domain.invalid
Subject: Re: [Ironruby-core] defined?(xxx) behaves differently when
called from Silverlight

The folder SL is installed into is the version; if you’re using SL2 it
should be C:\Program Files\Microsoft Silverlight\2.0.40115.0. SL3 Beta
is C:\Program Files\Microsoft Silverlight\3.0.40307.0.
I’m testing this from my Mac. I’ll be searching for the files using
find.

http://jimmy.schementi.com/silverlight/repro-defined.zip

Unzip that and double-click on the index.html file. The first line of
app.xap is defined?(System::Windows::Forms), and works fine. It also
works in the console. Let me know what happens for you.

Clicking on index.html shows a welcome message and the ironruby console,
so it doesn’t seem to bang.

Editing has some weird behaviour: when I type (, defined? gets erased.
Maybe totally unrelated, but this mean I can’t test in the console.

I’m a bit puzzled as why it fails. I’ll try to find some extra time to
investigate - may be related to the fact that I’m using Chiron on Mac ?

No idea what’s happening for the moment.

Thanks for the repro, Jimmy.

– Thibaut


#13

Woops, hit send too soon. I just tested it out on a Mac in FF3 and
Safari3, and nothing blew up and the console rendered fine. You’re
future mail said things work, so I guess I’m just confirming that your
prior installation was all-sorts-of-crazy.

Also, Chiron on the Mac wouldn’t cause this, as Chiron simply serves a
XAP file, and has nothing to do with the actual running of the SL app.

~js

From: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] On Behalf Of Thibaut
Barrère
Sent: Thursday, April 02, 2009 3:44 PM
To: removed_email_address@domain.invalid
Subject: Re: [Ironruby-core] defined?(xxx) behaves differently when
called from Silverlight

The folder SL is installed into is the version; if you’re using SL2 it
should be C:\Program Files\Microsoft Silverlight\2.0.40115.0. SL3 Beta
is C:\Program Files\Microsoft Silverlight\3.0.40307.0.
I’m testing this from my Mac. I’ll be searching for the files using
find.

http://jimmy.schementi.com/silverlight/repro-defined.zip

Unzip that and double-click on the index.html file. The first line of
app.xap is defined?(System::Windows::Forms), and works fine. It also
works in the console. Let me know what happens for you.

Clicking on index.html shows a welcome message and the ironruby console,
so it doesn’t seem to bang.

Editing has some weird behaviour: when I type (, defined? gets erased.
Maybe totally unrelated, but this mean I can’t test in the console.

I’m a bit puzzled as why it fails. I’ll try to find some extra time to
investigate - may be related to the fact that I’m using Chiron on Mac ?

No idea what’s happening for the moment.

Thanks for the repro, Jimmy.

– Thibaut


#14

Jb Evain wrote:

On 4/1/09, Thibaut Barrè²¥ removed_email_address@domain.invalid wrote:

Can anyone else reproduce that issue (or is it something known
already), or is my silverlight install messing up ?

Well, there’s no System.Windows.Froms.Control in silverlight to begin
with.

defined?(System::Windows::Application)

does work though.