Share via


TargetException="Non-static method requires a target."

Question

Wednesday, September 23, 2009 6:18 PM

 Here is my ErrorMessage + StackTrace;

System.Reflection.TargetException was unhandled by user code Message="Non-static method requires a target."

Source="mscorlib"

StackTrace:

at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)

at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)

at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)

at DynamicData_FieldTemplates_ManyToMany_EditField.DataSource_UpdatingOrInserting(Object sender, EntityDataSourceChangingEventArgs e) in

c:\Websites\WebAppAdmin\DynamicData\FieldTemplates\ManyToMany_Edit.ascx.cs:line 30

at System.Web.UI.WebControls.EntityDataSourceView.OnUpdating(EntityDataSourceChangingEventArgs e)

at System.Web.UI.WebControls.EntityDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)

at System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback)

InnerException:

public partial class DynamicData_FieldTemplates_ManyToMany_EditField : FieldTemplateUserControl

{

}

I have implemented David Ebbos manytomany field template. I used his ManyToMany project and inserted it into mine own. I am trying to model Websites that connect to many Databases. So I have a PJT(pure join table) that has int keys referencing Databases and Sites. I had cascades turned on for both FK relationships, but I suspected that you can't do that  and expect DD to update as expected. Can anybody help???

All replies (1)

Tuesday, May 11, 2010 4:47 PM

I was getting the same exception if I had a field throwing a validation exception, which was causing the value of e.Entity to be null. I simply added the following to the beginning of the method (in DynamicData\FieldTemplates\ManyToMany_Edit.ascx.cs), and so far so good. I don't know if that would also apply to your particular situation.

void DataSource_UpdatingOrInserting(object sender, EntityDataSourceChangingEventArgs e)
{
    if (e.Entity == null)
        return;
    // ...
}