I think (at first inspection) is that you are using a resultClass of "Foo". Change the statement to return the primitive type "double" as the resultClass. The exception is indicating a cast of double->Foo is not valid.
Chris On Fri, May 8, 2009 at 9:27 AM, Martin Wickman <martin.wick...@dapresy.com>wrote: > Hello > > I get "System.InvalidCastException: Specified cast is not valid" and the > following stacktrace: > > at System.Data.SqlClient.SqlBuffer.get_Double() > at System.Data.SqlClient.SqlDataReader.GetDouble(Int32 i) > at > IBatisNet.DataMapper.Commands.DataReaderDecorator.System.Data.IDataRecord.GetDouble(Int32 > i) > at > IBatisNet.DataMapper.TypeHandlers.DoubleTypeHandler.GetValueByIndex(ResultProperty > mapping, IDataReader dataReader) > at > IBatisNet.DataMapper.Configuration.ResultMapping.ResultProperty.GetDataBaseValue(IDataReader > dataReader) > at > IBatisNet.DataMapper.MappedStatements.ResultStrategy.AutoMapStrategy.Process(RequestScope > request, IDataReader& reader, Object resultObject) > at > IBatisNet.DataMapper.MappedStatements.ResultStrategy.ResultClassStrategy.Process(RequestScope > request, IDataReader& reader, Object resultObject) > at > IBatisNet.DataMapper.MappedStatements.MappedStatement.RunQueryForList[T](RequestScope > request, ISqlMapSession session, Object parameterObject, IList`1 > resultObject, RowDelegate`1 rowDelegate) > at > IBatisNet.DataMapper.MappedStatements.MappedStatement.ExecuteQueryForList[T](ISqlMapSession > session, Object parameterObject) > at IBatisNet.DataMapper.SqlMapper.QueryForList[T](String statementName, > Object parameterObject) > at Dapresy.RefDB.ServiceLibrary.DB.FooHelper.select() in > C:\...\DB\FooHelper.cs:line 11 > at UnitTests.AttributesTest.foo() in > C:\...\UnitTests\AttributesTest.cs:line 79 > > This is a simple as I could make the test case: > > Foo.xml (the sqlMap): > > <?xml version="1.0" encoding="UTF-8" ?> > <sqlMap > namespace="Foo" > xmlns="http://ibatis.apache.org/mapping" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:noNamespaceSchemaLocation="../iBatis/SqlMap.xsd"> > > <statements> > <select id="getFoo" resultClass="Foo"> > SELECT 1.2345 as d > </select> > </statements> > </sqlMap> > > Foo.cs (the test class): > > public class Foo > { > public double d = 0.0; > } > > mapper().QueryForList<Foo>("getFoo", null); > > As you see, this is an extremely simple example and it should of course > work. If I change the 'd' property to and int or string or whatever, it > works. This is the first time I used doubles with iBats. But using 'float' > or 'double' gives this error! > > Using iBatis .NET 1.6.[12] and SQL Server2.0. > > /Martin >