By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,835 Members | 1,454 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,835 IT Pros & Developers. It's quick & easy.

BusinessObject update on DetailsView - Exception "No parameterlessconstructor defined for this object"

P: n/a
I have the following business Object(s):

public class ParentObject
{
public ParentObject(string somestring)
{
...-
}

....

}

public class MyBusinessObject : global::ParentObject
{
public MyBusinessObject (string somestring)
: base(somestring)
{
...
}
// some properties and other stuff
}
On a page I have defined a ObjectDataSource for MyBusinessObject. It
has a select and update method. It has handlers for OnSelected,
OnSelecting, OnCreating, OnUpdating. It has select parameters.

Select works fine, I could work around the 'Parameterless constructor
exception' by doing:

protected void MyBusinessObjectDS_Creating(object sender,
ObjectDataSourceEventArgs e)
{
BO_MyBusinessObject mbo = new BO_MyBusinessObject(somestring);
e.ObjectInstance = mbo;
}

This works just fine!

PROBLEM is the update method!

In my <asp:DetailsViewcontrol I have defined a OnItemUpdating
EventHandler. This gets calls. After that I get the following
exception:

[MissingMethodException: No parameterless constructor defined for this
object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeTyp e type, Boolean
publicOnly, Boolean noCheck, Boolean& canBeCached,
RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean
fillCache) +103
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean
skipVisibilityChecks, Boolean fillCache) +268
System.Activator.CreateInstance(Type type, Boolean nonPublic) +66
System.Web.UI.WebControls.ObjectDataSourceView.Bui ldDataObject(Type
dataObjectType, IDictionary inputParameters) +39

System.Web.UI.WebControls.ObjectDataSourceView.Exe cuteUpdate(IDictionary
keys, IDictionary values, IDictionary oldValues) +1294
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary
values, IDictionary oldValues, DataSourceViewOperationCallback
callback) +78
System.Web.UI.WebControls.DetailsView.HandleUpdate (String
commandArg, Boolean causesValidation) +1152
System.Web.UI.WebControls.DetailsView.HandleEvent( EventArgs e,
Boolean causesValidation, String validationGroup) +440

I also have a Updating handler on my ObjectDataSource. BUT THIS
HANDLER GETS NEVER CALLED, IT CRASHES BEFORE!

Any idea, how I can update with a business object, that has
parameterized constructors??? (I need them, otherwise the objects
could be instantiated without being correctly initialized).

Many thanks for your suggestions

Tom

Oct 29 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
the ObjectDataSource Update,Iinsert, and Delete methods create an instance of
the TypeName to perform these actions. the TypeName object can not have any
contructor parametes as there is no way to define them.

you should make a new object (adapter) that hosts the methods, and creates
correct underlying business objects. its you can use the paramter collection
and the Updating... events to create the underlying objects. a bad practice
to put database methods in a buisiness object anyway, as you want seperation
of layers.

-- bruce (sqlwork.com)
"be************@gmail.com" wrote:
I have the following business Object(s):

public class ParentObject
{
public ParentObject(string somestring)
{
...-
}

....

}

public class MyBusinessObject : global::ParentObject
{
public MyBusinessObject (string somestring)
: base(somestring)
{
...
}
// some properties and other stuff
}
On a page I have defined a ObjectDataSource for MyBusinessObject. It
has a select and update method. It has handlers for OnSelected,
OnSelecting, OnCreating, OnUpdating. It has select parameters.

Select works fine, I could work around the 'Parameterless constructor
exception' by doing:

protected void MyBusinessObjectDS_Creating(object sender,
ObjectDataSourceEventArgs e)
{
BO_MyBusinessObject mbo = new BO_MyBusinessObject(somestring);
e.ObjectInstance = mbo;
}

This works just fine!

PROBLEM is the update method!

In my <asp:DetailsViewcontrol I have defined a OnItemUpdating
EventHandler. This gets calls. After that I get the following
exception:

[MissingMethodException: No parameterless constructor defined for this
object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeTyp e type, Boolean
publicOnly, Boolean noCheck, Boolean& canBeCached,
RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean
fillCache) +103
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean
skipVisibilityChecks, Boolean fillCache) +268
System.Activator.CreateInstance(Type type, Boolean nonPublic) +66
System.Web.UI.WebControls.ObjectDataSourceView.Bui ldDataObject(Type
dataObjectType, IDictionary inputParameters) +39

System.Web.UI.WebControls.ObjectDataSourceView.Exe cuteUpdate(IDictionary
keys, IDictionary values, IDictionary oldValues) +1294
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary
values, IDictionary oldValues, DataSourceViewOperationCallback
callback) +78
System.Web.UI.WebControls.DetailsView.HandleUpdate (String
commandArg, Boolean causesValidation) +1152
System.Web.UI.WebControls.DetailsView.HandleEvent( EventArgs e,
Boolean causesValidation, String validationGroup) +440

I also have a Updating handler on my ObjectDataSource. BUT THIS
HANDLER GETS NEVER CALLED, IT CRASHES BEFORE!

Any idea, how I can update with a business object, that has
parameterized constructors??? (I need them, otherwise the objects
could be instantiated without being correctly initialized).

Many thanks for your suggestions

Tom

Oct 29 '08 #2

P: n/a
On 29 Okt., 18:11, bruce barker
<brucebar...@discussions.microsoft.comwrote:
the ObjectDataSource Update,Iinsert, and Delete methods create an instance of
the TypeName to perform these actions. the TypeName object can not have any
contructor parametes as there is no way to define them.

you should make a new object (adapter) that hosts the methods, and creates
correct underlying business objects. its *you can use the paramter collection
and the Updating... events to create the underlying objects. a bad practice
to put database methods in a buisiness object anyway, as you want seperation
of layers.

-- bruce (sqlwork.com)

"bednarz.tho...@gmail.com" wrote:
I have the following business Object(s):
public class ParentObject
{
* *public ParentObject(string somestring)
* *{
* * ...-
* *}
* ....
}
public class MyBusinessObject : global::ParentObject
{
* * public MyBusinessObject (string somestring)
* * * * : base(somestring)
* * {
* * * * * ...
* * }
* * // some properties and other stuff
}
On a page I have defined a ObjectDataSource for MyBusinessObject. It
has a select and update method. It has handlers for OnSelected,
OnSelecting, OnCreating, OnUpdating. It has select parameters.
Select works fine, I could work around the 'Parameterless constructor
exception' by doing:
protected void MyBusinessObjectDS_Creating(object sender,
ObjectDataSourceEventArgs e)
{
* * * * BO_MyBusinessObject mbo = new BO_MyBusinessObject(somestring);
* * * * e.ObjectInstance = mbo;
}
This works just fine!
PROBLEM is the update method!
In my <asp:DetailsViewcontrol I have defined a OnItemUpdating
EventHandler. This gets calls. After that I get the following
exception:
[MissingMethodException: No parameterless constructor defined for this
object.]
* *System.RuntimeTypeHandle.CreateInstance(RuntimeTy pe type, Boolean
publicOnly, Boolean noCheck, Boolean& canBeCached,
RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
* *System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean
fillCache) +103
* *System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean
skipVisibilityChecks, Boolean fillCache) +268
* *System.Activator.CreateInstance(Type type, Boolean nonPublic) +66
* *System.Web.UI.WebControls.ObjectDataSourceView.Bu ildDataObject(Type
dataObjectType, IDictionary inputParameters) +39
System.Web.UI.WebControls.ObjectDataSourceView.Exe cuteUpdate(IDictionary
keys, IDictionary values, IDictionary oldValues) +1294
* *System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary
values, IDictionary oldValues, DataSourceViewOperationCallback
callback) +78
* *System.Web.UI.WebControls.DetailsView.HandleUpdat e(String
commandArg, Boolean causesValidation) +1152
* *System.Web.UI.WebControls.DetailsView.HandleEvent (EventArgs e,
Boolean causesValidation, String validationGroup) +440
I also have a Updating handler on my ObjectDataSource. BUT THIS
HANDLER GETS NEVER CALLED, IT CRASHES BEFORE!
Any idea, how I can update with a business object, that has
parameterized constructors??? (I need them, otherwise the objects
could be instantiated without being correctly initialized).
Many thanks for your suggestions
Tom
Hi Bruce,

Thanks for that feedback. Do you know of any link that shows some
'best practice' when working with Business Objects and ASP.NET? I have
some experience with Java and Application Servers like JBoss, Tomcat,
Geronimo etc. Seems all to be a bit different with MS technology.

Tom
Oct 29 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.