Reflection Exception

Posts   
 
    
deathwish
User
Posts: 56
Joined: 07-Nov-2006
# Posted on: 07-Nov-2006 21:24:30   

Hi,

When i add custom properties to the entityclasses and then bind to those properties in a datagrid, i get an exception when going to the designer in VS 2005:

"System.Reflection.TargetInvocationException: Property accessor 'SiteCode' on object 'Data.EntityClasses.StationEntity' threw the following exception: 'Object reference not set to an instance of an object ....' "

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 07-Nov-2006 22:17:05   
Frans Bouma | Lead developer LLBLGen Pro
deathwish
User
Posts: 56
Joined: 07-Nov-2006
# Posted on: 10-Nov-2006 11:47:57   

Hey,

SQL Server 2005 / VS 2005 / LLBLGen Pro v2.0.0.0 Demo Final / Default Template

The SiteStationEntity.cs class contains the following:


// __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
public string SiteCode
{
    get { return this.Site.SiteCode; }
}

public string SiteName
{
    get { return this.Site.Name; }
}
// __LLBLGENPRO_USER_CODE_REGION_END
#endregion

The Html contains the following:


<radg:radgrid>
<columns>
<radg:gridboundcolumn datafield="SiteName" headertext="Site Name" sortexpression="SiteName" uniquename="SiteName">
</columns>
</radg:radgrid>

The page runs fine but when going to the designer in VS 2005, the following error occurs: http://www.emediait.co.za/designer%20error.png

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 10-Nov-2006 12:45:44   

You've to test if Site is null. In design mode, Site will be null, as no action to the db will be made.

Frans Bouma | Lead developer LLBLGen Pro
deathwish
User
Posts: 56
Joined: 07-Nov-2006
# Posted on: 14-Nov-2006 10:17:11   

Hey,

http://www.emediait.co.za/reflection%20exception.png


// __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
public string FullNumber
{
    get 
    {
        if(this.CountryRegion == null)
            return string.Format("({0}) {1}", this.AreaCode, this.LocalNumber); 

        return string.Format("+{0} ({1}) {2}", this.CountryRegion.DiallingCode, this.AreaCode, this.LocalNumber ); 
    }
}
// __LLBLGENPRO_USER_CODE_REGION_END


<radg:gridboundcolumn datafield="FullNumber" headertext="Phone Number" sortexpression="FullNumber"  uniquename="FullNumber">

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 14-Nov-2006 10:31:47   

That's a .net error, which, looking at your code I don't understand, as you've specified 3 parameters and also the indexes are specified properly. If you run that code in a small console app, it should give the same error.

The thing is that the grid at DESIGN TIME works with the properties on an entity as if it's runtime, i.e. reads the values of them. If something goes wrong while doing that, the exception shows up in the grid/bound control in the DESIGNER. So it might look like a designer issue, it is an execption originating in your code.

Frans Bouma | Lead developer LLBLGen Pro
deathwish
User
Posts: 56
Joined: 07-Nov-2006
# Posted on: 14-Nov-2006 13:55:05   

Hi Otis,

Sorry i forgot to mention, that property was just an example. I seem to get reflection exceptions with all my custom properties.

The webform runs perfectly and doesn't return an error, guess i'll just leave the designer for now. Who needs it anyway.

Thanks very much for the great support.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 14-Nov-2006 14:02:37   

The reason you get design-time errors might be that you trigger lazy loading, and you do that in your example:

public string FullNumber { get { if(this.CountryRegion == null) return string.Format("({0}) {1}", this.AreaCode, this.LocalNumber);

    return string.Format("+{0} ({1}) {2}", this.**CountryRegion**.DiallingCode, this.AreaCode, this.LocalNumber );
}

}

Frans Bouma | Lead developer LLBLGen Pro