Friday, 8 May 2009

"Exception has been thrown by the target of an invocation." when creating a user in the ASP.NET Web Administration Tool

One of the requirements for an ASP.NET application we recently created at Oakton (for a certain NSW government department) was that deletes of lookups (including users) should be soft-deleted by using an "IsDeleted" flag.

To fulfill this requirement, we added an additional column to the automatically generated "aspnet_Users" table simply called "IsDeleted" so we could filter out these deleted users from lookup lists (e.g. dropdowns and autocomplete textboxes).

Edits worked fine after this change, but the creation of new users from the built-in ASP.NET Administration Tool was failing with the following exception:

Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) 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.Web.Administration.WebAdminMembershipProvider.CallWebAdminMembershipProviderHelperMethodOutParams(String methodName, Object[] parameters, Type[] paramTypes) at System.Web.Administration.WebAdminMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) at System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() at System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e) at System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.WebControls.Wizard.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

This error message wasn't particularly helpful, so I checked out SQL Profiler to get the real error message turns out that the IsDeleted column didn't have a default on it, so the insert of the record was failing on the call to the aspnet_Membership_CreateUser stored procedure.

The simple fix was to just add a default for the new column - otherwise custom columns you add to the generated asp.net membership tables will cause the provider to fail when creating new users. This will of course not just happen with the built in tool, but any page using the built in ASP.NET membership provider.

3 comments:

Robin said...

David, Thanks for your posting. My Exception pop up come from and ACT op up box, when tyring to start Outlook (home computer). ACT has been crashing, so I go into control panel>admin>services>flip the SLQ ACT7 switch back to "start" and then usually we are good to go. I have a conflcit somewhere - thought it was the WD backup program. May not be. Any ideas? Thanks!! Robin

Unknown said...

Robin,

Did you ever figure out the cause? I received the same message today.

Everything was fine until installed my WD drive with backup software yesterday.

Ali Şahin said...

David,
I really dont understand what u mentioned on the last paragraph.
-The simple fix was to just add a default for the new column -
How can i add a default for the new column? Can you explain it? I added identityNumber column like yours.