Mscorlib:0:in `ThrowArgumentException' error

Hi all,

I’m having an error that I can’t figure out what it is:

This portion of code works perfectly by itself

config = [{:QuantityPer => “#{2+2}”}]
config.each { |xx| if xx[:QuantityPer].include? ‘#{’ then
xxx = xx[:QuantityPer].to_s
xxx = xxx[2…(xxx.size-2)]
puts xxx
xx[:QuantityPer] = eval(xxx)
puts xx[:QuantityPer]
end
}

prints
2+2
4
as supposed

However in the middle of a routine throws this error:

2+2
mscorlib:0:in ThrowArgumentException': An item with the same key has already been added. (ArgumentError) from mscorlib:0:inInsert’
from ./xxx_master.rb:641:in `eval’

the line 641 actually is the one corresponding to the beginning of the
“config.each” statement and not the one for the eval…

Could someone point me in the right direction?

Thank you in advance

Eduardo blumenfeld

Any Ideas?

Thank you in advance,

Eduardo B.

Hi Eduardo,

What is config’s type? Is it a regular Ruby list, or is it some sort of
collection returned from a .NET library? Maybe it’s one of the items in
the
config - could you provide a listing of the items in the config when you
run
the code? It would also help if I could some of the surrounding routine.

I do find it hard to believe that’s exactly what your code looks like,
unless you actually have a list of hashes where every key is
:QuantityPer.
As an example, the following breaks:

config = [{:QuantityPer => “#{2+2}”}, {:foo => “bar”}]

… the rest of your code here …

Prints the following:

2+2
4
NoMethodError: undefined method include?' for nil:NilClass from (irb):28 from (irb):28:ineach’
from (irb):28
from C:/IronRuby/lib/ruby/1.8/irb.rb:150:in eval_input' from C:/IronRuby/lib/ruby/1.8/irb.rb:257:insignal_status’
from C:/IronRuby/lib/ruby/1.8/irb.rb:147:in eval_input' from C:/IronRuby/lib/ruby/1.8/irb.rb:146:ineval_input’
from C:/IronRuby/lib/ruby/1.8/irb.rb:70:in start' from C:/IronRuby/lib/ruby/1.8/irb.rb:69:incatch’
from C:/IronRuby/lib/ruby/1.8/irb.rb:69:in `start’
from C:/IronRuby/bin/irb:13

Regards,

Charles

Thank you Charles for the answer,

config is an active record produced list, an array of rows brought from
a sql table that has one of its attributes (table column) =>
:QuantityPer

This is the portion of the code I’m using

config = Term.find_by_sql(“sp_someStoredProc @someparameter=#{param1}”)
config.each { |xx| if xx[:QuantityPer].nil? then nil else
if xx[:QuantityPer].include? ‘#{’ then
xxx = xx[:QuantityPer].to_s
xxx = xxx[2…(xxx.size-2)]
puts xxx

error line

xx[:QuantityPer] = eval(xxx)

error line

puts xx[:QuantityPer]
end
end
}

The error line line is the one I’m showing
EUREKA!!!

While I was answering you, I think figured out the problem, (I have to
test it though)

The problem has to do with the fact that the active record model has
attr_readonly set as:

class Term < ActiveRecord::Base
attr_readonly
end

What is puzzling to me is the cryptic error, not having a complete trace
of
the troubling gem (in this case the active_record) with this kind of
errors

Thank you, Thank you

I will post the results of the test as soon as It works!

Eduardo B.

Hi all,

Unfortunately it didn’t work,

I believe that there is some kind of problem in mscorlib
when you try to do an eval inside a loop with active record objects.

Eduardo B. wrote:

Thank you Charles for the answer,

config is an active record produced list, an array of rows brought from
a sql table that has one of its attributes (table column) =>
:QuantityPer

This is the portion of the code I’m using

config = Term.find_by_sql(“sp_someStoredProc @someparameter=#{param1}”)
config.each { |xx| if xx[:QuantityPer].nil? then nil else
if xx[:QuantityPer].include? ‘#{’ then
xxx = xx[:QuantityPer].to_s
xxx = xxx[2…(xxx.size-2)]
puts xxx

=> “some_proc(argument,argument2)”

I see in the console the xxx variable…
if at this point I put this code:

puts “#{xxx}”

it just prints (again) the xxx variable without
evaluating it at all

if at this point I put this code instead:

aaa = eval(xxx)

then I get this error:

mscorlib:0:in ThrowArgumentException': An item with the same key has already been added. (ArgumentError) from mscorlib:0:inInsert’

Any pointers?

Is that an mscorlib bug?

Hi Eduardo,

This looks like it could be a bug in IronRuby… or possibly the
ActiveRecord adapter. That exception that is being thrown is from a
Hashtable or Dictionary; a value is being inserted with an existing key.
Typical Ruby code won’t ever use a .NET specific type such as Hashtable
or
Dictionary (of course), which makes me think that this might be a bug in
IronRuby… or possibly your ActiveRecord adapter (assuming it’s tailor
made
for IronRuby).

I’d hate to make you jump through hoops, but it would be great if you
could
lend me a hand in figuring this one out. If you could send me a small
repro, that would be great; baring that, I have some questions for you:

What sort of AR adapter are you using?

Could you give me the “actual” stack trace for this exception? This
should
do the trick:

begin

… the line of code that throws …

rescue Exception => e

use the following to get the actual .NET/System.Exception stack

trace:
puts e.StackTrace
end

Thanks,

Charles

Hi all,

I finally solved the issue:
By calling another procedure and within that procedure do the eval, it
works perfectly.

However, this seems to be a bug anyways…

Regards,

Eduardo