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

B

bednarz.thomas

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:DetailsView> control 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(RuntimeType 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.BuildDataObject(Type
dataObjectType, IDictionary inputParameters) +39

System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(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
 
B

bruce barker

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)


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:DetailsView> control 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(RuntimeType 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.BuildDataObject(Type
dataObjectType, IDictionary inputParameters) +39

System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(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
 
T

Thommy

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)

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:DetailsView> control 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(RuntimeType 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.BuildDataObject(Type
dataObjectType, IDictionary inputParameters) +39
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(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

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
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top