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

Skip to first unread message

Jakub Malý

Oct 19, 2013, 11:50:38 AM10/19/13
to mybatis...@googlegroups.com

Hi, I am trying to set up IBatis.NET. 

I have downloaded the sources fromhttp://mybatisnet.googlecode.com/svn/branches/ibatis-1-maintenance/src.

This is my initialization

DomDaoManagerBuilder builder = new DomDaoManagerBuilder();
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);

I have also asked this question on SO, but maybe this mailing list is a better place. 

Thanks, Jakub. 

César Iglesias

Oct 19, 2013, 12:14:38 PM10/19/13
to mybatis...@googlegroups.com

Hi, I think the problem is the inheritance from IDao. ICustomerDAO should inherits from IDao instead BaseDAO.


You received this message because you are subscribed to the Google Groups "mybatisnet-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatisnet-us...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jakub Malý

Oct 19, 2013, 12:21:51 PM10/19/13
to mybatis...@googlegroups.com

Hi César,

that does not solve the issue

this line executes fine:


IDao customerDao = daoManager[typeof(ICustomerDao)];


customerDao implements IDao.

It is this line which fails:


ICustomerDao cd = (ICustomerDao) customerDao;


I tried adding ICustomerDao: IDao just to be sure and it behaves the same.



Reply all
Reply to author
0 new messages