If I do this:
Template delTemplate = delsite.Templates[0] as Template;
this._templateService.DeleteTemplate(delTemplate);
or this:
User delUser = this._userService.GetUserByUsernameAndEmail(username, email);
//Delete the user
this._userService.DeleteUser(delUser);
I get: System.NullReferenceException: Object reference not set to an instance of an object.
When in debug, I step through the operation and there is a template in 'delTemplate' and a user in 'delUser'. I get the same error for both.
Any ideas?
I will keep checking.
Just noticed in debug that there is a TemplateProxy:
delTemplate = {TemplateProxy46bce1d1a9484632b8be63cbd636c0f4}
How do I get the template I want to delete and delete it?
It shouldn't matter if you have a proxy or a real instance. What is the stacktrace of the exception?
[NullReferenceException: Object reference not set to an instance of an object.]
Cuyahoga.Modules.CatMod.Web.CatMod.BlitzSite(String username, String email, String sitename) +381
Cuyahoga.Modules.CatMod.Web.CatMod.btnBlitz_Click(Object sender, EventArgs e) +165
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
I have been able to completely remove a site and its nodes and sections. Now I wish to remove the Template and the user that has been associated with the site. It is at this stage I get an error.
Has anyone created any SQL to remove a site instance completely?
You have probably checked it already, but something must be null in the code behind, looking at the stack trace. Maybe the services? Or is there an inner exception somewhere?
There is nothing null. I test by doing this:
Template delTemplate = delsite.Templates[0] as Template;
this._templateService.DeleteTemplate(delTemplate);
The delTemplate = {TemplateProxy46bce1d1a9484632b8be63cbd636c0f4} and still throws the System.NullReferenceException: Object reference not set to an instance of an object.
I have followed this back to where it deletes. Then it fails.
If you follow it back to where it deletes (CommonDao.DeleteObject?), is there something null over there? The session? Or CommonDao?
So, what was going wrong here?
martijnbSo, what was going wrong here?
I stripped out everything and coded it again. Then it worked.
The objects I was trying to delete had values (I could see them) but I was getting the same Null errors. So I cleanded everything out, performed a rebuild and coded again. Then it worked.
I believe it was me that was going wrong! I think that I may have had null '_templateService' or '_userService'. But it works now.
I have a rough module that accepts registrations with a site name, email address and template selection, creates a user, emails them login details and creates them a site based upon the template they selected.
I can also delete the user and site completely via admin. I am still not happy with it 100%. It leaves one or 2 orphan (unassigned) files.