Spring.Net 错误:PropertyAccessExceptions。 Spring.Core.TypeMismatchException:无法转换属性值

发布于 2024-12-23 15:09:02 字数 1554 浏览 1 评论 0原文

我有一个类:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期以后 2024-12-30 15:09:02

您的配置中有一个明显的缺陷:

<!-- ... snip ... -->   
<object id="GenUser" type="carnamespace.GenericUser, carassembly"> <!-- assemblyname after comma -->
  <!-- 
  Use ref instead of value!
  <property name="GenericImplementation" value="GenericImplementation"/>
  -->
  <property name="GenericImplementation" ref="GenericImplementation"/>
</object>

这也给了我一个带有嵌套 TypeMismatchExceptionPropertyAccessExceptions

我很难重现您的问题,因为您的代码无法编译。如果这不能解决您的问题,请发布编译代码示例。另外,确保您至少可以在代码中构造对象,例如:

public void ConstructFromCode()
{
    var drive = new Drive();
    var genImp = new GenericImplementation {DriveImplementation = drive};
    var genUser = new GenericUser {GenericImplementation = genImp};
}

There is one obvious flaw in your configuration:

<!-- ... snip ... -->   
<object id="GenUser" type="carnamespace.GenericUser, carassembly"> <!-- assemblyname after comma -->
  <!-- 
  Use ref instead of value!
  <property name="GenericImplementation" value="GenericImplementation"/>
  -->
  <property name="GenericImplementation" ref="GenericImplementation"/>
</object>

This gave me a PropertyAccessExceptions with a nested TypeMismatchException 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.:

public void ConstructFromCode()
{
    var drive = new Drive();
    var genImp = new GenericImplementation {DriveImplementation = drive};
    var genUser = new GenericUser {GenericImplementation = genImp};
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文