GridView bug?

P

PJ6

I have a data source that returns an array of objects casted as an interface
type. The interface type is all I have, I do not have the implementing class
to cast as.

Below this is what GridView gives me in response.

What is it doing invoking Activator.CreateInstance? I can see where you
would want data copied to edit and perform validation when editing, but
that's what MemberwiseClone and Serialize/Deserialze is for. And I'm not
editing, this error is thrown on DataBind.

Also, the actual class that implements the interface *does* have a
parameterless constructor.

Is this a bug?

Paul

Server Error in '/' Application.
--------------------------------------------------------------------------------

No parameterless constructor defined for this object.


[MissingMethodException: No parameterless constructor defined for this
object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean
publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor,
Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean
fillCache) +86
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean
skipVisibilityChecks, Boolean fillCache) +230
System.Activator.CreateInstance(Type type, Boolean nonPublic) +67

System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +139

System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1247
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments,
DataSourceViewSelectCallback callback) +19
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
System.Web.UI.WebControls.GridView.DataBind() +4
VehicleWorkBench.Registrations.PopulateControls() in
C:\Resources\DEV\projects\VehicleWorkBench\VehicleWorkBench\Registrations.aspx.vb:17
VehicleWorkBench.Registrations.OnLoad(EventArgs e) in
C:\Resources\DEV\projects\VehicleWorkBench\VehicleWorkBench\Registrations.aspx.vb:10
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
 
M

miher

PJ6 said:
I have a data source that returns an array of objects casted as an
interface
type. The interface type is all I have, I do not have the implementing
class
to cast as.

Below this is what GridView gives me in response.

What is it doing invoking Activator.CreateInstance? I can see where you
would want data copied to edit and perform validation when editing, but
that's what MemberwiseClone and Serialize/Deserialze is for. And I'm not
editing, this error is thrown on DataBind.

Also, the actual class that implements the interface *does* have a
parameterless constructor.

Is this a bug?

Paul

Server Error in '/' Application.
--------------------------------------------------------------------------------

No parameterless constructor defined for this object.


[MissingMethodException: No parameterless constructor defined for this
object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean
publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle&
ctor,
Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean
fillCache) +86
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean
skipVisibilityChecks, Boolean fillCache) +230
System.Activator.CreateInstance(Type type, Boolean nonPublic) +67

System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod
method, Boolean disposeInstance, Object& instance) +139

System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments
arguments) +1247
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments,
DataSourceViewSelectCallback callback) +19
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
System.Web.UI.WebControls.GridView.DataBind() +4
VehicleWorkBench.Registrations.PopulateControls() in
C:\Resources\DEV\projects\VehicleWorkBench\VehicleWorkBench\Registrations.aspx.vb:17
VehicleWorkBench.Registrations.OnLoad(EventArgs e) in
C:\Resources\DEV\projects\VehicleWorkBench\VehicleWorkBench\Registrations.aspx.vb:10
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627


Hi,

From this stack i would say that Your problem is around Your datasource.
When You use ObjectDataSource it will try to create an instance of You
datasource class to be able to call the select method on it(unless the
select method is static). For this reason it expects to find a parameterless
constructor on the datasource. If You don't have/want to make any You can
handle the ObjectCreating (
http://msdn.microsoft.com/en-us/lib...controls.objectdatasource.objectcreating.aspx )
event to create an object as You wish.

Hope this helps.
-Zsolt
 
P

PJ6

Ahh good eye.

It was a static method but I'm just going to dump using the designer.

Problem solved!

Thanks,
Paul

miher said:
PJ6 said:
I have a data source that returns an array of objects casted as an
interface
type. The interface type is all I have, I do not have the implementing
class
to cast as.

Below this is what GridView gives me in response.

What is it doing invoking Activator.CreateInstance? I can see where you
would want data copied to edit and perform validation when editing, but
that's what MemberwiseClone and Serialize/Deserialze is for. And I'm not
editing, this error is thrown on DataBind.

Also, the actual class that implements the interface *does* have a
parameterless constructor.

Is this a bug?

Paul

Server Error in '/' Application.
--------------------------------------------------------------------------------

No parameterless constructor defined for this object.


[MissingMethodException: No parameterless constructor defined for this
object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean
publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle&
ctor,
Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean
fillCache) +86
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean
skipVisibilityChecks, Boolean fillCache) +230
System.Activator.CreateInstance(Type type, Boolean nonPublic) +67

System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod
method, Boolean disposeInstance, Object& instance) +139

System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments
arguments) +1247
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments,
DataSourceViewSelectCallback callback) +19
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
System.Web.UI.WebControls.GridView.DataBind() +4
VehicleWorkBench.Registrations.PopulateControls() in
C:\Resources\DEV\projects\VehicleWorkBench\VehicleWorkBench\Registrations.aspx.vb:17
VehicleWorkBench.Registrations.OnLoad(EventArgs e) in
C:\Resources\DEV\projects\VehicleWorkBench\VehicleWorkBench\Registrations.aspx.vb:10
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627


Hi,

From this stack i would say that Your problem is around Your datasource.
When You use ObjectDataSource it will try to create an instance of You
datasource class to be able to call the select method on it(unless the
select method is static). For this reason it expects to find a parameterless
constructor on the datasource. If You don't have/want to make any You can
handle the ObjectCreating (
http://msdn.microsoft.com/en-us/lib...controls.objectdatasource.objectcreating.aspx )
event to create an object as You wish.

Hope this helps.
-Zsolt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top