SelfServicing TypedList NullReferenceException

Posts   
 
    
mklinker
User
Posts: 14
Joined: 25-Mar-2008
# Posted on: 24-Sep-2009 19:34:38   

First off, here's the standard requested information:

Designer Ver: 2.6 Final Runtime Ver: 2.6.8.804 Template: Self-Servicing Database: Sql Server 2008

I'm trying to define and retrieve a dynamic typed list at run time and have a null reference exception being thrown from the support classes DLL. I've confirmed that none of the values I'm passing are null, or contain null (besides the Transaction object I'm not using). Here is my definition of the view and releations.

Note - ReaderFields is class that simply stores constant field values so I don't have to reference reader[0].

            var fields = new ResultsetFields(ReaderFields.FieldCount);
            fields.DefineField(RootApplicationFields.RootApplicationId, ReaderFields.RootApplicationId);
            fields.DefineField(RootApplicationFields.ApplicationRef, ReaderFields.ApplicationRef);
            fields.DefineField(CriminalTxFields.CriminalTxId, ReaderFields.CriminalTxId);
            fields.DefineField(CriminalApplicationFields.Created, ReaderFields.Created);
            fields.DefineField(CriminalApplicationFields.CreatedBy, ReaderFields.CreatedBy);
            fields.DefineField(CriminalApplicationFields.LastModified, ReaderFields.LastModifed);
            fields.DefineField(CriminalApplicationFields.LastModifiedBy, ReaderFields.LastModifiedBy);
            fields.DefineField(CriminalApplicationFields.CriminalApplicationId, ReaderFields.CriminalApplicationId);

            var joins = new RelationCollection();
            joins.Add(RootApplicationEntity.Relations.CriminalApplicationEntityUsingCriminalApplicationId);
            joins.Add(CriminalApplicationEntity.Relations.CriminalTxEntityUsingCriminalApplicationId);

            var ipe = new PredicateExpression(RootApplicationFields.CustOrgUnitId == orgUnitId);
            ipe.AddWithAnd(RootApplicationFields.Created > DateTime.Now.AddYears(-2));

            var dao = new TypedListDAO();
            using (IDataReader reader = dao.GetAsDataReader(null, fields, ipe, joins, CommandBehavior.CloseConnection, 0, false))

And now the stack trace for the exception:

System.NullReferenceException was unhandled by user code
  Message="Object reference not set to an instance of an object."
  Source="SD.LLBLGen.Pro.ORMSupportClasses.NET20"
  StackTrace:
       at SD.LLBLGen.Pro.ORMSupportClasses.PersistenceCore.AddInheritanceRelatedElementsToQueryElementsForDynamicList(InheritanceHierarchyType hierarchyType, IList fields, IPredicateExpression filter, IRelationCollection relations, IInheritanceInfoProvider infoProvider, String forEntityName)
       at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.CreateQueryFromElements(ITransaction transactionToUse, IEntityFields fields, IPredicate filter, IRelationCollection relations, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize)
       at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsDataReader(ITransaction transactionToUse, IEntityFields fields, IPredicate filter, IRelationCollection relations, CommandBehavior readerBehavior, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize)
       at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsDataReader(ITransaction transactionToUse, IEntityFields fields, IPredicate filter, IRelationCollection relations, CommandBehavior readerBehavior, Int32 maxNumberOfItemsToReturn, Boolean allowDuplicates)
       at CRMoveCustomer.Converters.CriminalApplicationConverter.ConvertCriminalApplications(Int32 orgUnitId) in D:\projects\cr6\CRMoveCustomer\CRMoveCustomer\Converters\CriminalApplicationConverter.cs:line 64
       at CRMoveCustomer.ConvertCustomer.ProcessApplications() in D:\projects\cr6\CRMoveCustomer\CRMoveCustomer\ConvertCustomer.cs:line 117
       at CRMoveCustomer.Form1.ApplicationWorkerDoWork(Object sender, DoWorkEventArgs e) in D:\projects\cr6\CRMoveCustomer\CRMoveCustomer\Form1.cs:line 91
       at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
  InnerException:

Any suggestions would be greatly appreciated, I've been searching around and can't find anything that seems to indicate what is causing this exception. If any additional information would be beneficial, please let me know and I'll post whatever is required.

Thanks for reading!

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 24-Sep-2009 21:29:14   

Are your ReaderFields definitions DEFINITLEY in sync with the actual fields ? And does the SQL get generated and run, or does it not get that far...?

Matt

mklinker
User
Posts: 14
Joined: 25-Mar-2008
# Posted on: 24-Sep-2009 22:09:56   

The ReaderFields is defined as below and really is just a collection of constants and shouldn't make any difference to the code I posted (or at least, I wouldn't think).

        private class ReaderFields
        {
            public const int FieldCount = 9;

            public const int RootApplicationId = 1;
            public const int Created = 2;
            public const int CriminalTxId = 3;
            public const int CreatedBy = 4;
            public const int LastModifed = 5;
            public const int LastModifiedBy = 6;
            public const int CriminalApplicationId = 7;
            public const int ApplicationRef = 8;
        }

And no, it seems to be throwing the exception while attempting to generate the query. I can set a breakpoint right on the dao.GetAsDataReader and step over with no query displayed in the output.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Sep-2009 07:37:15   

mklinker wrote:

The ReaderFields is defined as below and really is just a collection of constants and shouldn't make any difference to the code I posted (or at least, I wouldn't think).

As a matter of fact that is the problem simple_smile

mklinker wrote:

[code] private class ReaderFields { public const int FieldCount = 9;

Your class says that you have 9 fields but you only have 8. In the dynamicList you are saying that the list will have 9 fields but you are only defining 8.

So, just change your FieldCount field value to 8.

David Elizondo | LLBLGen Support Team
mklinker
User
Posts: 14
Joined: 25-Mar-2008
# Posted on: 25-Sep-2009 16:30:55   

If I set the field count to the number of fields I'm actually using, I get a exception stating that the IndexOutOfRangeException on the line DefineField on the last field. Wouldn't this be due to 0 based index?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Sep-2009 17:31:04   

mklinker wrote:

If I set the field count to the number of fields I'm actually using, I get a exception stating that the IndexOutOfRangeException on the line DefineField on the last field. Wouldn't this be due to 0 based index?

Exactly, I forgot that.

Your custom clase should look like:

private class ReaderFields
        {
            public const int FieldCount = 8;

            public const int RootApplicationId = 0;
            public const int Created = 1;
            public const int CriminalTxId = 2;
            public const int CreatedBy = 3;
            public const int LastModifed = 4;
            public const int LastModifiedBy = 5;
            public const int CriminalApplicationId = 6;
            public const int ApplicationRef = 7;
        }
David Elizondo | LLBLGen Support Team
mklinker
User
Posts: 14
Joined: 25-Mar-2008
# Posted on: 25-Sep-2009 17:33:21   

That seems to have done the trick, thanks for pointing that out to me. Not sure why it never occurred to me though ><

Great support once again!