TypedList Iterate Problem

Posts   
 
    
MikeG
User
Posts: 23
Joined: 17-Dec-2006
# Posted on: 16-Feb-2008 18:58:32   

Hi,

I am seeking to use a TypedList, and iterate through the results. When I run this code I'll post below, the compiler throws this error:


Unable to cast object of type 'DAL.TypedListClasses.ManifestationsBoardRow' to type 'DAL.TypedListClasses.ManifestationBoardRow'.

This error is thrown here:


foreach (ManifestationBoardRow dr in manifestations)

The entire block of code is here:


    protected void Page_Load(object sender, EventArgs e)
    {
        ISortExpression sorter = new SortExpression(ManifestationsFields.CreatedDateTime | SortOperator.Descending);
        int maxRows = 10;

        bool allowDuplicates = false;

        ManifestationsBoardTypedList manifestations =
            ManifestationController.GetManifestationsBoard(maxRows, ManifestationsFields.CreatedDateTime, SortOperator.Descending, allowDuplicates);

        StringBuilder html = new StringBuilder();

        if (manifestations != null)
        {
            html.Append("Count: " + manifestations.Count + "<BR>");
            html.Append("<table border='0'>");

            foreach (ManifestationBoardRow dr in manifestations)
            {
                html.Append("<tr><td>Username:</td><td>" + dr.UserName + "</td></tr>");
                html.Append("<tr><td>Title:</td><td>" + dr.Title + "</td></tr>");
                html.Append("<tr><td>Manifested:</td><td>" + dr.Manifestation + "</td></tr>");
            }
        }
        else
        {
            html.Append("<TR><TD colspan='2'>There are no manifestations to display.  Quick, go manifest something, and tell us about it!  :-)</TD></TR>");
        }

        html.Append("</table>");

        manifestationsGgridDisplayLabel.Text = html.ToString();
    }

and:


        public static ManifestationsBoardTypedList GetManifestationsBoard(int maxRows, EntityField sortEntityField, SortOperator sortOperator, bool allowDuplicates)
        {
            ManifestationsBoardTypedList manifestationsBoard = new ManifestationsBoardTypedList();

            ISortExpression sorter = new SortExpression(sortEntityField | sortOperator);

            manifestationsBoard.Fill(maxRows, sorter, allowDuplicates);

            if (manifestationsBoard.Count > 0)
            {
                return manifestationsBoard;
            }
            else
            {
                return null;
            }
        }

Can you please help me understand what is happening here, and how I can have this work?

Also, I was able to have it work this way:


            for (index = 0; index < manifestations.Count; index++)
            {
                html.Append("<tr><td>Username:</td><td>" + manifestations[index].UserName + "</td></tr>");
                html.Append("<tr><td>Title:</td><td>" + manifestations[index].Title + "</td></tr>");
                html.Append("<tr><td>Manifested:</td><td>" + manifestations[index].Manifestation + "</td></tr>");
            }

And would love to also have a deeper understanding of why the foreach isn't working.

Thank you very much, Mike

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 16-Feb-2008 20:20:13   

MikeG wrote:

This error is thrown here:


foreach (ManifestationBoardRow dr in manifestations)

That should works. Could you please post the exception stack trace , also the LLBLGen and runtimeLibraries version.

MikeG
User
Posts: 23
Joined: 17-Dec-2006
# Posted on: 16-Feb-2008 20:27:13   

goose wrote:

MikeG wrote:

This error is thrown here:


foreach (ManifestationBoardRow dr in manifestations)

That should works. Could you please post the exception stack trace , also the LLBLGen and runtimeLibraries version.

Thank you Goose. Here is the stack trace:


"   at WebUserControls_ManifestationsGridl.Page_Load(Object sender, EventArgs e) in c:\\Documents and Settings\\Administrator\\My Documents\\Code\\iManifested\\WebSite\\WebUserControls\\ManifestationsBoard.ascx.cs:line 39\r\n   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)\r\n   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)\r\n   at System.Web.UI.Control.OnLoad(EventArgs e)\r\n   at System.Web.UI.Control.LoadRecursive()\r\n   at System.Web.UI.Control.LoadRecursive()\r\n   at System.Web.UI.Control.LoadRecursive()\r\n   at System.Web.UI.Control.LoadRecursive()\r\n   at System.Web.UI.Control.LoadRecursive()\r\n   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)"

Is this helpful?

Cheers, Mike

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 16-Feb-2008 20:49:14   

Hi Mike,

Is that all the stack trace? Could you please post the LLBLGenPro version and runtime libraries version? When this issue throw? After you did something?

MikeG
User
Posts: 23
Joined: 17-Dec-2006
# Posted on: 16-Feb-2008 23:11:45   

goose wrote:

Hi Mike,

Is that all the stack trace? Could you please post the LLBLGenPro version and runtime libraries version? When this issue throw? After you did something?

Hi Goose,

I am using version 2.5.0.0.

This is thrown when it tries to iterate through the TypedList. I dont recall doing anything, or not anything I am aware of.

Thanks Mike

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-Feb-2008 18:32:01   

Hmmm... Could you please regenerate the project in a empty folder and make a tiny test with the same snippet?

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 18-Feb-2008 10:35:49   

Are there two versions of the compiled code somewhere in the application? That's what the error suggests...

Frans Bouma | Lead developer LLBLGen Pro