IBatis: "Unable to cast object of type 'Castle.Proxies.IDaoProxy' to type 'SysProt.Dao.ICustomerDao'."

Posted by j_maly on Stack Overflow See other posts from Stack Overflow or by j_maly
Published on 2013-10-19T13:05:07Z Indexed on 2013/10/19 15:54 UTC
Read the original article Hit count: 1188

Filed under:
|
|

I am trying to set up IBatis.NET. I have downloaded the sources from http://mybatisnet.googlecode.com/svn/branches/ibatis-1-maintenance/src.

This is my initialization

DomDaoManagerBuilder builder = new DomDaoManagerBuilder();
builder.Configure("dao.config");
IDaoManager daoManager = DaoManager.GetInstance("SqlMapDao");
customerDao = daoManager[typeof(ICustomerDao)];
ICustomerDao cd = (ICustomerDao) customerDao;

The last line throws InvalidCastException "Unable to cast object of type 'Castle.Proxies.IDaoProxy' to type 'SysProt.Dao.ICustomerDao'."

I am not sure, what I did wrong, my dao.config files contains

Here are the definitions of the classes/interfaces:

public interface ICustomerDao
{
    Customer Load(long id);
}

public class CustomerDao: BaseDao, ICustomerDao
{
    public Customer Load(long id)
    {
        throw new NotImplementedException();
    }
}

public class BaseDao : IDao
{
    protected DaoSession GetContext()
    {
        IDaoManager daoManager = DaoManager.GetInstance(this);
        return (daoManager.LocalDaoSession as DaoSession);
    }
}

© Stack Overflow or respective owner

Related posts about mybatis

Related posts about ibatis