emacinty
02-12-2005, 10:43 PM
Hello.
I use the MethodInvokingFactoryObject in order to obtain a string
value which is being assigned as the property of an object.
In some circumstances, the string returned is null. This results in the
following:
Additional information: Error creating object with name 'stringHolder' defined in 'blah' : Error setting property values: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are:
[Spring.Objects.TypeMismatchException: Cannot convert property value of type [Missing] to required type [System.String] for property 'string',
It seems that when "null" is returned, the method invoker switches
this to an alternative "Void" value, which confuses the assignment
of the property value. However, surely assignment of null should
be fine?
The attempt above is in a simple example I stripped out of my
application, to verify that this wasn't something silly I was doing.
I've included the xml and C# code below.
Thanks for any advice,
Ewan
PS I'm using code from CVS from the end of January.
-----
2 c# classes, really trivial (& contrived):
namespace SpringTest
{
public class StringHolder
{
private string _str;
public string String
{
set
{
_str = value;
}
}
}
}
namespace SpringTest
{
public class StringReturner
{
private string _str;
public string String
{
set
{
_str = value;
}
get
{
return _str;
}
}
public string returnString()
{
return _str;
}
}
}
And the relevant bit of xml:
<object name="stringReturner" type="SpringTest.StringReturner">
<!-- property name="string">
<value>A string</value>
</property -->
</object>
<object name="stringHolder" type="SpringTest.StringHolder">
<property name="string">
<object type="Spring.Objects.Factory.Config.MethodInvokingFactor yObject">
<property name="targetMethod">
<value>returnString</value>
</property>
<property name="targetObject">
<ref object="stringReturner"/>
</property>
</object>
</property>
</object>
The invoking code just needs to try to create "stringHolder".
If the commented-out part of the "stringReturner" object definition
is reinstated, it obviously works fine.
I use the MethodInvokingFactoryObject in order to obtain a string
value which is being assigned as the property of an object.
In some circumstances, the string returned is null. This results in the
following:
Additional information: Error creating object with name 'stringHolder' defined in 'blah' : Error setting property values: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are:
[Spring.Objects.TypeMismatchException: Cannot convert property value of type [Missing] to required type [System.String] for property 'string',
It seems that when "null" is returned, the method invoker switches
this to an alternative "Void" value, which confuses the assignment
of the property value. However, surely assignment of null should
be fine?
The attempt above is in a simple example I stripped out of my
application, to verify that this wasn't something silly I was doing.
I've included the xml and C# code below.
Thanks for any advice,
Ewan
PS I'm using code from CVS from the end of January.
-----
2 c# classes, really trivial (& contrived):
namespace SpringTest
{
public class StringHolder
{
private string _str;
public string String
{
set
{
_str = value;
}
}
}
}
namespace SpringTest
{
public class StringReturner
{
private string _str;
public string String
{
set
{
_str = value;
}
get
{
return _str;
}
}
public string returnString()
{
return _str;
}
}
}
And the relevant bit of xml:
<object name="stringReturner" type="SpringTest.StringReturner">
<!-- property name="string">
<value>A string</value>
</property -->
</object>
<object name="stringHolder" type="SpringTest.StringHolder">
<property name="string">
<object type="Spring.Objects.Factory.Config.MethodInvokingFactor yObject">
<property name="targetMethod">
<value>returnString</value>
</property>
<property name="targetObject">
<ref object="stringReturner"/>
</property>
</object>
</property>
</object>
The invoking code just needs to try to create "stringHolder".
If the commented-out part of the "stringReturner" object definition
is reinstated, it obviously works fine.