Hi all. I have a question that probably belongs on a users mailing list
but
I could not find one.
I get the following error when trying to use my IronRuby windsor
registration script:
System.InvalidOperationException: can’t convert
Castle::Core::ComponentModel into Castle::Core::ComponentModel
I assume this has something to do with the fact that newing up an object
in
IronRuby isn’t the same thing as newing it up in C#.
def component(options)
throw :classIsRequired if !options.has_key?(:class)
klass = options[:class].to_clr_type
if options.has_key?(:service)
service = options[:service].to_clr_type
else
service = klass
end
if options.has_key?(:name)
name = options[:name]
else
name = klass.class.name.underscore.lowercase
end
model = ComponentModel.new(name, service, klass)
if options.has_key?(:parameters)
parameters = options[:parameters]
parameters.each do |p|
model.Parameters.Add(p.key, p.value)
end
end
$container.Register(ComponentRegistration.new(model))
end
Hi all. I have a question that probably belongs on a users mailing list
but I could not find one.
I get the following error when trying to use my IronRuby windsor
registration script:
System.InvalidOperationException: can’t convert
Castle::Core::ComponentModel into Castle::Core::ComponentModel
I assume this has something to do with the fact that newing up an object
in IronRuby isn’t the same thing as newing it up in C#.
def component(options)
throw :classIsRequired if !options.has_key?(:class)
klass = options[:class].to_clr_type
if options.has_key?(:service)
service = options[:service].to_clr_type
else
service = klass
end
if options.has_key?(:name)
name = options[:name]
else
name = klass.class.name.underscore.lowercase
end
model = ComponentModel.new(name, service, klass)
if options.has_key?(:parameters)
parameters = options[:parameters]
parameters.each do |p|
model.Parameters.Add(p.key, p.value)
end
end
$container.Register(ComponentRegistration.new(model))
I’m using the hosting API.
This is the entire method:
public void Load(IWindsorContainer container, TextReader reader)
{
var runtime = Ruby.CreateRuntime();
ScriptEngine engine = Ruby.GetEngine(runtime);
var ctx = Ruby.GetExecutionContext(runtime);
ctx.DefineReadOnlyGlobalVariable(“container”, container);
def component(options)
throw :classIsRequired if !options.has_key?(:class)
klass = options[:class].to_clr_type
if options.has_key?(:service)
service = options[:service].to_clr_type
else
service = klass
end
if options.has_key?(:name)
name = options[:name]
else
name = klass.class.name.underscore.lowercase
end
model = ComponentModel.new(name, service, klass)
if options.has_key?(:parameters)
parameters = options[:parameters]
parameters.each do |p|
model.Parameters.Add(p.key, p.value)
end
end
$container.Register(ComponentRegistration.new(model))
end";
I tried that and no luck.
It doesn’t seem that the assembly is not being loaded properly. I’m
able to
use methods on the objects fine in the script. However, it is that last
call to the $container.Register(ComponentRegistration.new(model)) where
for
some reason it won’t work.
ComponentRegistration.new() takes a ComponentModel. The error seems to
indicate that it is receiving a ComponentModel even with the same
namespace
prefixes but somehow it’s not able to use it.
The assembly seems to be loaded twice into 2 different loader contexts.
“require†with a simple name (as opposed to strong name “Assembly,
Version=…, Culture=…, PublicKeyToken=…“ or Kernel#load_assembly) uses
Assembly.LoadFrom to load the assembly. If you have a reference to the
assembly in your C# host that loads it using Assembly.Load, which loads
to a different context. So you might end up loading the assembly (and
types that are defined there) twice. The runtime then as two different
Type objects for a single logical type.
2009/3/18 Nathan S. <[email protected]mailto:[email protected]>
I dont know if this helps, but this is the full output of the test:
ComponentLoaderRegisteringComponentContext.ShouldRegisterComponent :
Failed
CT_INIT: Object
UPDATED: Object
CreateInstanceSingleton affected=1 rules=0
UPDATED: Object
CreateInstanceSingleton affected=1 rules=0
CT_INIT: File::Constants
CT_INIT: IO
CT_INIT: File
UPDATED: Object
CreateInstanceSingleton affected=1 rules=0
MT_INIT: Kernel
MT_INIT: Object
MT_INIT:
MT_INIT: Module
MT_INIT: Class
MT_INIT:
UPDATED: Object
CreateInstanceSingleton affected=5 rules=1
MT_INIT:
LOADER: Loading assembly ‘Motorpool.Calendar.Web.Test, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null’ and type ‘’
MT_INIT: Symbol
MT_INIT: Enumerable
MT_INIT: Hash
MT_INIT: Microsoft::Scripting::Actions::TypeTracker
MT_INIT: Microsoft::Scripting::Actions::TypeGroup
System.InvalidOperationException: can’t convert
Castle::Core::ComponentModel into Castle::Core::ComponentModel
at CallSite.Target(Closure , CallSite , RubyMethodScope , Object ,
Object )
at
System.Dynamic.UpdateDelegates.UpdateAndExecute3<T0,T1,T2,TRet>(CallSite
site, T0 arg0, T1 arg1, T2 arg2) in
C:\git\ironruby\ndp\fx\src\Core\Microsoft\Scripting\Actions\UpdateDelegates.Generated.cs:
line 509
at ℑℜ;component;;10;(Closure , Object , Proc , Object )
at CallSite.Target(Closure , CallSite , RubyScope , Object , Hash )
at
System.Dynamic.UpdateDelegates.UpdateAndExecute3<T0,T1,T2,TRet>(CallSite
site, T0 arg0, T1 arg1, T2 arg2) in
C:\git\ironruby\ndp\fx\src\Core\Microsoft\Scripting\Actions\UpdateDelegates.Generated.cs:
line 509
at ℑℜ;#;;0;(Closure , Scope , LanguageContext )
at Microsoft.Scripting.Runtime.LegacyScriptCode.Run() in
C:\git\ironruby\Merlin\Main\Runtime\Microsoft.Scripting\Runtime\LegacyScriptCode.cs:
line 43
at Microsoft.Scripting.SourceUnit.Execute() in
C:\git\ironruby\Merlin\Main\Runtime\Microsoft.Scripting\SourceUnit.cs:
line 239
at Microsoft.Scripting.Hosting.ScriptSource.Execute() in
C:\git\ironruby\Merlin\Main\Runtime\Microsoft.Scripting\Hosting\ScriptSource.cs:
line 138
at Motorpool.Calendar.Service.ComponentLoader.Load(IWindsorContainer
container, TextReader reader) in ComponentLoader.cs: line 64
at
Motorpool.Calendar.Web.Test.ComponentLoaderRegisteringComponentContext.ShouldRegisterComponent()
in ComponentLoaderRegisteringComponentContext.cs: line 26
It doesn’t seem that the assembly is not being loaded properly. I’m
able to use methods on the objects fine in the script. However, it is
that last call to the
$container.Register(ComponentRegistration.new(model)) where for some
reason it won’t work.
ComponentRegistration.new() takes a ComponentModel. The error seems to
indicate that it is receiving a ComponentModel even with the same
namespace prefixes but somehow it’s not able to use it.
2009/3/18 Ivan Porto C.
<[email protected]mailto:[email protected]>
You can try using the LoadAssembly method on the runtime object
This is the entire method:
public void Load(IWindsorContainer container, TextReader
reader)
{
var runtime = Ruby.CreateRuntime();
ScriptEngine engine =
Ruby.GetEngine(runtime);
var ctx = Ruby.GetExecutionContext(runtime);
ctx.DefineReadOnlyGlobalVariable(“container”,
container);
def component(options)
throw :classIsRequired if !options.has_key?(:class)
klass = options[:class].to_clr_type
if options.has_key?(:service)
service = options[:service].to_clr_type
else
service = klass
end
if options.has_key?(:name)
name = options[:name]
else
name = klass.class.name.underscore.lowercase
end
model = ComponentModel.new(name, service, klass)
if options.has_key?(:parameters)
parameters = options[:parameters]
parameters.each do |p|
model.Parameters.Add(p.key, p.value)
end
end
$container.Register(ComponentRegistration.new(model))
throw :classIsRequired if !options.has_key?(:class)
klass = options[:class].to_clr_type
if options.has_key?(:service)
service = options[:service].to_clr_type
else
service = klass
end
if options.has_key?(:name)
name = options[:name]
else
name = klass.class.name.underscore.lowercase
end
model = ComponentModel.new(name, service, klass)
if options.has_key?(:parameters)
parameters = options[:parameters]
parameters.each do |p|
model.Parameters.Add(p.key, p.value)
end
end
$container.Register(ComponentRegistration.new(model))
2009/3/18 Nathan S. <[email protected]mailto:[email protected]>
I dont know if this helps, but this is the full output of the test:
ComponentLoaderRegisteringComponentContext.ShouldRegisterComponent :
Failed
CT_INIT: Object
UPDATED: Object
CreateInstanceSingleton affected=1 rules=0
UPDATED: Object
CreateInstanceSingleton affected=1 rules=0
CT_INIT: File::Constants
CT_INIT: IO
CT_INIT: File
UPDATED: Object
CreateInstanceSingleton affected=1 rules=0
MT_INIT: Kernel
MT_INIT: Object
MT_INIT:
MT_INIT: Module
MT_INIT: Class
MT_INIT:
UPDATED: Object
CreateInstanceSingleton affected=5 rules=1
MT_INIT:
LOADER: Loading assembly ‘Motorpool.Calendar.Web.Test, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null’ and type ‘’
MT_INIT: Symbol
MT_INIT: Enumerable
MT_INIT: Hash
MT_INIT: Microsoft::Scripting::Actions::TypeTracker
MT_INIT: Microsoft::Scripting::Actions::TypeGroup
System.InvalidOperationException: can’t convert
Castle::Core::ComponentModel into Castle::Core::ComponentModel
at CallSite.Target(Closure , CallSite , RubyMethodScope , Object ,
Object )
at
System.Dynamic.UpdateDelegates.UpdateAndExecute3<T0,T1,T2,TRet>(CallSite
site, T0 arg0, T1 arg1, T2 arg2) in
C:\git\ironruby\ndp\fx\src\Core\Microsoft\Scripting\Actions\UpdateDelegates.Generated.cs:
line 509
at ℑℜ;component;;10;(Closure , Object , Proc , Object )
at CallSite.Target(Closure , CallSite , RubyScope , Object , Hash )
at
System.Dynamic.UpdateDelegates.UpdateAndExecute3<T0,T1,T2,TRet>(CallSite
site, T0 arg0, T1 arg1, T2 arg2) in
C:\git\ironruby\ndp\fx\src\Core\Microsoft\Scripting\Actions\UpdateDelegates.Generated.cs:
line 509
at ℑℜ;#;;0;(Closure , Scope , LanguageContext )
at Microsoft.Scripting.Runtime.LegacyScriptCode.Run() in
C:\git\ironruby\Merlin\Main\Runtime\Microsoft.Scripting\Runtime\LegacyScriptCode.cs:
line 43
at Microsoft.Scripting.SourceUnit.Execute() in
C:\git\ironruby\Merlin\Main\Runtime\Microsoft.Scripting\SourceUnit.cs:
line 239
at Microsoft.Scripting.Hosting.ScriptSource.Execute() in
C:\git\ironruby\Merlin\Main\Runtime\Microsoft.Scripting\Hosting\ScriptSource.cs:
line 138
at Motorpool.Calendar.Service.ComponentLoader.Load(IWindsorContainer
container, TextReader reader) in ComponentLoader.cs: line 64
at
Motorpool.Calendar.Web.Test.ComponentLoaderRegisteringComponentContext.ShouldRegisterComponent()
in ComponentLoaderRegisteringComponentContext.cs: line 26
It doesn’t seem that the assembly is not being loaded properly. I’m
able to use methods on the objects fine in the script. However, it is
that last call to the
$container.Register(ComponentRegistration.new(model)) where for some
reason it won’t work.
ComponentRegistration.new() takes a ComponentModel. The error seems to
indicate that it is receiving a ComponentModel even with the same
namespace prefixes but somehow it’s not able to use it.
2009/3/18 Ivan Porto C.
<[email protected]mailto:[email protected]>
You can try using the LoadAssembly method on the runtime object
This is the entire method:
public void Load(IWindsorContainer container, TextReader
reader)
{
var runtime = Ruby.CreateRuntime();
ScriptEngine engine =
Ruby.GetEngine(runtime);
var ctx = Ruby.GetExecutionContext(runtime);
ctx.DefineReadOnlyGlobalVariable(“container”,
container);
throw :classIsRequired if !options.has_key?(:class)
klass = options[:class].to_clr_type
if options.has_key?(:service)
service = options[:service].to_clr_type
else
service = klass
end
if options.has_key?(:name)
name = options[:name]
else
name = klass.class.name.underscore.lowercase
end
model = ComponentModel.new(name, service, klass)
if options.has_key?(:parameters)
parameters = options[:parameters]
parameters.each do |p|
model.Parameters.Add(p.key, p.value)
end
end
$container.Register(ComponentRegistration.new(model))
2009/3/18 Nathan S. <[email protected]mailto:[email protected]>
I dont know if this helps, but this is the full output of the test:
ComponentLoaderRegisteringComponentContext.ShouldRegisterComponent :
Failed
CT_INIT: Object
UPDATED: Object
CreateInstanceSingleton affected=1 rules=0
UPDATED: Object
CreateInstanceSingleton affected=1 rules=0
CT_INIT: File::Constants
CT_INIT: IO
CT_INIT: File
UPDATED: Object
CreateInstanceSingleton affected=1 rules=0
MT_INIT: Kernel
MT_INIT: Object
MT_INIT:
MT_INIT: Module
MT_INIT: Class
MT_INIT:
UPDATED: Object
CreateInstanceSingleton affected=5 rules=1
MT_INIT:
LOADER: Loading assembly ‘Motorpool.Calendar.Web.Test, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null’ and type ‘’
MT_INIT: Symbol
MT_INIT: Enumerable
MT_INIT: Hash
MT_INIT: Microsoft::Scripting::Actions::TypeTracker
MT_INIT: Microsoft::Scripting::Actions::TypeGroup
System.InvalidOperationException: can’t convert
Castle::Core::ComponentModel into Castle::Core::ComponentModel
at CallSite.Target(Closure , CallSite , RubyMethodScope , Object ,
Object )
at
System.Dynamic.UpdateDelegates.UpdateAndExecute3<T0,T1,T2,TRet>(CallSite
site, T0 arg0, T1 arg1, T2 arg2) in
C:\git\ironruby\ndp\fx\src\Core\Microsoft\Scripting\Actions\UpdateDelegates.Generated.cs:
line 509
at ℑℜ;component;;10;(Closure , Object , Proc , Object )
at CallSite.Target(Closure , CallSite , RubyScope , Object , Hash )
at
System.Dynamic.UpdateDelegates.UpdateAndExecute3<T0,T1,T2,TRet>(CallSite
site, T0 arg0, T1 arg1, T2 arg2) in
C:\git\ironruby\ndp\fx\src\Core\Microsoft\Scripting\Actions\UpdateDelegates.Generated.cs:
line 509
at ℑℜ;#;;0;(Closure , Scope , LanguageContext )
at Microsoft.Scripting.Runtime.LegacyScriptCode.Run() in
C:\git\ironruby\Merlin\Main\Runtime\Microsoft.Scripting\Runtime\LegacyScriptCode.cs:
line 43
at Microsoft.Scripting.SourceUnit.Execute() in
C:\git\ironruby\Merlin\Main\Runtime\Microsoft.Scripting\SourceUnit.cs:
line 239
at Microsoft.Scripting.Hosting.ScriptSource.Execute() in
C:\git\ironruby\Merlin\Main\Runtime\Microsoft.Scripting\Hosting\ScriptSource.cs:
line 138
at Motorpool.Calendar.Service.ComponentLoader.Load(IWindsorContainer
container, TextReader reader) in ComponentLoader.cs: line 64
at
Motorpool.Calendar.Web.Test.ComponentLoaderRegisteringComponentContext.ShouldRegisterComponent()
in ComponentLoaderRegisteringComponentContext.cs: line 26
It doesn’t seem that the assembly is not being loaded properly. I’m
able to use methods on the objects fine in the script. However, it is
that last call to the
$container.Register(ComponentRegistration.new(model)) where for some
reason it won’t work.
ComponentRegistration.new() takes a ComponentModel. The error seems to
indicate that it is receiving a ComponentModel even with the same
namespace prefixes but somehow it’s not able to use it.
2009/3/18 Ivan Porto C.
<[email protected]mailto:[email protected]>
You can try using the LoadAssembly method on the runtime object
This is the entire method:
public void Load(IWindsorContainer container, TextReader
reader)
{
var runtime = Ruby.CreateRuntime();
ScriptEngine engine =
Ruby.GetEngine(runtime);
var ctx = Ruby.GetExecutionContext(runtime);
ctx.DefineReadOnlyGlobalVariable(“container”,
container);
def component(options)
throw :classIsRequired if !options.has_key?(:class)
klass = options[:class].to_clr_type
if options.has_key?(:service)
service = options[:service].to_clr_type
else
service = klass
end
if options.has_key?(:name)
name = options[:name]
else
name = klass.class.name.underscore.lowercase
end
model = ComponentModel.new(name, service, klass)
if options.has_key?(:parameters)
parameters = options[:parameters]
parameters.each do |p|
model.Parameters.Add(p.key, p.value)
end
end
$container.Register(ComponentRegistration.new(model))
throw :classIsRequired if !options.has_key?(:class)
klass = options[:class].to_clr_type
if options.has_key?(:service)
service = options[:service].to_clr_type
else
service = klass
end
if options.has_key?(:name)
name = options[:name]
else
name = klass.class.name.underscore.lowercase
end
model = ComponentModel.new(name, service, klass)
if options.has_key?(:parameters)
parameters = options[:parameters]
parameters.each do |p|
model.Parameters.Add(p.key, p.value)
end
end
$container.Register(ComponentRegistration.new(model))