Hi,
1. In a class named DBUser there is a property named FullNameByLastName.
This property does not have a backing field. It combines two backing fields
an returns a string result:
public virtual string FullNameByLastName
{
get
{
return m_LastName + ", " + m_FirstName;
}
}
2. An ObjectDataSource is used. Its SelectMethod returns a generic
collection ( List<DBUser>)
3. The ObjectDataSource is assigned/bound to a GridView.
4. FullNameByLastName is bound to a column in the GridView.
<asp:GridView ID="ListGridView" runat="server">
<Columns>
<asp:BoundField
DataField="FullNameByLastName"
SortExpression="FullNameByLastName"
HeaderStyle-HorizontalAlign="Left"
ItemStyle-HorizontalAlign="Left"
HeaderText="<%$Label:TITLE %>"
/>
Etc...
The exception I get is shown below. In brief it is: 'FullNameByLastName' on
object 'WorkforceLogic.Core.Domain.DBUser' threw the following
exception:'Object does not match target type.']
I only get this exception on class properties what don't have backing fields
such as LastNameByFullName. All other fields bind without the exception.
What do you think? Is this an issue with ObjectDataSource, GridView, or the
NHibernate? Or?
Best Regards,
--
Mike
Mike McIntyre [MVP]
http://www.getdotnetcode.com
[TargetException: Object does not match target type.]
System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
+2284281
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean
skipVisibilityChecks) +114
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object
component) +86
[TargetInvocationException: Property accessor 'FullNameByLastName' on object
'WorkforceLogic.Core.Domain.DBUser' threw the following exception:'Object
does not match target type.']
System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object
component) +370
System.Web.UI.WebControls.BoundField.GetValue(Control controlContainer)
+201
System.Web.UI.WebControls.BoundField.OnDataBindField(Object sender,
EventArgs e) +60
System.Web.UI.Control.OnDataBinding(EventArgs e) +99
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +206
System.Web.UI.Control.DataBind() +12
System.Web.UI.Control.DataBindChildren() +216
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +216
System.Web.UI.Control.DataBind() +12
System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32
dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState,
Boolean dataBind, Object dataItem, DataControlField[] fields,
TableRowCollection rows, PagedDataSource pagedDataSource) +221
System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable
dataSource, Boolean dataBinding) +3004
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable
data) +59
System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)
+11
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable
data) +111
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments,
DataSourceViewSelectCallback callback) +29
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()
+69
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +41
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360