Spring.Core.TypeMismatchException: Cannot convert property of type [...] to required type [...]

StackOverflow https://stackoverflow.com/questions/16711223

  •  30-05-2022
  •  | 
  •  

Question

my problem is that I cannot do any test anymore after I made a tfs update on the project I'm working on. Before the update it worked but now I'm getting a Spring.Core.TypeMismatchException everytime I run the ContextRegistry.GetContext() method in my testclass' Init() method.

The only changes on MyProjectDao were changes within its methods and the attributes were added. And a service has been added to the SpringContext.xml.

This is the exception I get:

System.Configuration.ConfigurationErrorsException: System.Configuration.ConfigurationErrorsException: Error creating context 'spring.root': PropertyAccessExceptionsException (1 errors); nested PropertyAccessExceptions are:

[Spring.Core.TypeMismatchException: Cannot convert property value of type [CompositionAopProxy_f81c875c2f994f88bb773f5743050b67] to required type [MyProject.Dao.MyProjectDao] for property 'MyProjectDao'., Inner Exception: Spring.Core.TypeMismatchException: Cannot convert property value of type [CompositionAopProxy_f81c875c2f994f88bb773f5743050b67] to required type [MyProject.Dao.MyProjectDao] for property 'MyProjectDao'. at Spring.Core.TypeConversion.TypeConversionUtils.ConvertValueIfNecessary(Type requiredType, Object newValue, String propertyName) in f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Core\TypeConversion\TypeConversionUtils.cs:MyProject 211.] ---> Spring.Objects.Factory.ObjectCreationException: Error creating object with name 'MyProjectService' defined in 'file [C:\Projects\MyProject\MyProject.NET\test\MyProject.Service.Test\bin\Debug\SpringContext.xml] line 147' : Error setting property values: PropertyAccessExceptionsException (1 errors); nested PropertyAccessExceptions are: [Spring.Core.TypeMismatchException: Cannot convert property value of type [CompositionAopProxy_f81c875c2f994f88bb773f5743050b67] to required type [MyProject.Dao.MyProjectDao] for property 'MyProjectDao'., Inner Exception: Spring.Core.TypeMismatchException: Cannot convert property value of type [CompositionAopProxy_f81c875c2f994f88bb773f5743050b67] to required type [MyProject.Dao.MyProjectDao] for property 'MyProjectDao'. at Spring.Core.TypeConversion.TypeConversionUtils.ConvertValueIfNecessary(Type requiredType, Object newValue, String propertyName) in f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Core\TypeConversion\TypeConversionUtils.cs:MyProject 211.] ---> Spring.Objects.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested PropertyAccessExceptions are: [Spring.Core.TypeMismatchException: Cannot convert property value of type [CompositionAopProxy_f81c875c2f994f88bb773f5743050b67] to required type [MyProject.Dao.MyProjectDao] for property 'MyProjectDao'., Inner Exception: Spring.Core.TypeMismatchException: Cannot convert property value of type [CompositionAopProxy_f81c875c2f994f88bb773f5743050b67] to required type [MyProject.Dao.MyProjectDao] for property 'MyProjectDao'. at Spring.Core.TypeConversion.TypeConversionUtils.ConvertValueIfNecessary(Type requiredType, Object newValue, String propertyName) in f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Core\TypeConversion\TypeConversionUtils.cs:MyProject 211.].

MyProjectDao class looks like this:

namespace MyProject.Dao
{
    [DataAccessObject]
    [Transaction(TransactionPropagation.Mandatory)]
    public class MyProjectDao : IMyProjectDao
    {
        public ISessionFactory SessionFactory { private get; set; }

        // ... Methods ... 
    }
}

The IMyProjectDao interface:

namespace MyProject.Dao
{
    public interface IMyProjectDao
    {
        // ... Methods ... 
    }
}

this is a part of my SpringContext.xml

<!-- ######################## -->
<!--            DAO           -->
<!-- ######################## -->

<object id="MyProjectDao" type="MyProject.Dao.MyProjectDao, MyProject">
    <property name="SessionFactory" ref="SessionFactory" />
</object>

<!-- ######################## -->
<!--          Service         -->
<!-- ######################## -->

<object id="MyProjectService" type="MyProject.Service.MyProjectService, MyProject">
    <property name="MyProjectDao"       ref="MyProjectDao" />
    <property name="PersistenceService" ref="PersistenceService" />
    <property name="DeletedObjectCache" ref="DeletedObjectCache" />
</object>
Was it helpful?

Solution

Are you using the interface 'IMyProjectDao' in the MyProjectService for the MyProjectDao property or are you using the class 'MyProjectDao'.

If you use the class change it to the interface.

Change your property in the MyProjectService class from:

public MyProjectDao MyProjectDao { get; set; }

To

public IMyProjectDao MyProjectDao { get; set; }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top