Spring.Net 错误:PropertyAccessExceptions。 Spring.Core.TypeMismatchException:无法转换属性值
我有一个类:
public GenericImplementation:IGeneric<ICar>
{
public IDrive DriveImplementation {get;set;}
}
和一个接口:
public interface IGeneric<ICar>
{
}
public interface IDrive<T>
{
void Drive(T);
}
和一个实现:
public class Drive:IDrive<ICar>
{
public void Drive(ICar car)
{
}
}
和一个使用 IGeneric 的类:
public class GenericUser:IUser
{
public IGeneric GenericImplementation {get;set;}
}
所有类都存在于 carnamespace 下。
在 spring.net 配置中,我有:
<object id="Drive" type="carnamespace.Drive, carnamespace"/>
<object id="GenericImplementation" type="carnamespace.GenericImplementation, carnamespace">
<property name="DriveImplementation" ref="Drive"/>
</object>
<object id="GenUser" type="carnamespace.GenericUser, carnamespace">
<property name="GenericImplementation" value="GenericImplementation"/>
</object>
但我不断收到此错误:
PropertyAccessExceptionsException (1 errors); nested PropertyAccessExceptions are:
[Spring.Core.TypeMismatchException: Cannot convert property value of type [carnamespace.GenericImplementation] to required type [carnamespace.IGeneric`1[[carnamespace.ICar, carnamespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]] for property 'GenericImplementation'., Inner Exception: Spring.Core.TypeMismatchException:
Can有人请帮我理解决议是什么?
I have a class:
public GenericImplementation:IGeneric<ICar>
{
public IDrive DriveImplementation {get;set;}
}
And an interface:
public interface IGeneric<ICar>
{
}
public interface IDrive<T>
{
void Drive(T);
}
And an implementation:
public class Drive:IDrive<ICar>
{
public void Drive(ICar car)
{
}
}
And a class that uses IGeneric:
public class GenericUser:IUser
{
public IGeneric GenericImplementation {get;set;}
}
All classes exist under carnamespace.
In spring.net configuration, I have:
<object id="Drive" type="carnamespace.Drive, carnamespace"/>
<object id="GenericImplementation" type="carnamespace.GenericImplementation, carnamespace">
<property name="DriveImplementation" ref="Drive"/>
</object>
<object id="GenUser" type="carnamespace.GenericUser, carnamespace">
<property name="GenericImplementation" value="GenericImplementation"/>
</object>
But I keep getting this error:
PropertyAccessExceptionsException (1 errors); nested PropertyAccessExceptions are:
[Spring.Core.TypeMismatchException: Cannot convert property value of type [carnamespace.GenericImplementation] to required type [carnamespace.IGeneric`1[[carnamespace.ICar, carnamespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]] for property 'GenericImplementation'., Inner Exception: Spring.Core.TypeMismatchException:
Can someone please help me understand what the resolution is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的配置中有一个明显的缺陷:
这也给了我一个带有嵌套
TypeMismatchException
的PropertyAccessExceptions
。我很难重现您的问题,因为您的代码无法编译。如果这不能解决您的问题,请发布编译代码示例。另外,确保您至少可以在代码中构造对象,例如:
There is one obvious flaw in your configuration:
This gave me a
PropertyAccessExceptions
with a nestedTypeMismatchException
too.I've had a hard time reproducing your problem, because your code doesn't compile. If this doesn't solve your problem, please post a compiling code sample. Also, make sure you can at least construct your objects in code, e.g.: