Developer forum

Forum » Development » Error on deleting content page via API (Primary item must have a value before committing)

Error on deleting content page via API (Primary item must have a value before committing)

Allan Iversen
Allan Iversen
Reply

Hi,

 

We are getting this error when deleting content page with the PageService:

 

PageService pageService = new PageService();

pageService.DeletePage(page.ID);

 

Exception:

Primary item must have a value before committing

Dynamicweb.SystemTools.RecycleBin.RecycleBin.Commit()

   at Dynamicweb.SystemTools.RecycleBin.RecycleBin.Dispose(Boolean disposing)

   at Dynamicweb.SystemTools.RecycleBin.RecycleBin.Dispose()

   at Dynamicweb.Content.PageService.MoveToBin(Page obj)

   at Dynamicweb.Content.PageService.DeletePage(Int32 pageId)

 

Why do we get this error - are we able to delete the page without moving it to the recycle bin?

 

Allan


Replies

 
Nicolai Pedersen
Reply

You should be able to delete using this - the API will always move to recycle bin though. So some kind of bug it is...

Can you dump a screen dump of how the page is placed in the tree? Does it have language versions, masters anything elser?

Thanks, Nicolai

 
Allan Iversen
Allan Iversen
Reply

Hi Nicolai,

Yes - see attached image.

No language versioning or masters.

We want to delete these "job"-pages.

Allan

page_tree.png
 
Allan Iversen
Allan Iversen
Reply

Hi again,

Do you have info enough for debugging? - if seen as an error - when do you think we can have a bug fix?

Any workaround for page delete using the API?

Allan

 
Nicolai Pedersen
Reply

Hi Allan

I've ordered TFS#46794 - but I cannot give you an estimate just yet. But hopefully next Tuesday.

BR Nicolai

 
Allan Iversen
Allan Iversen
Reply

Ok - thanks!

Allan

 
Allan Iversen
Allan Iversen
Reply

Hi there!

TFS#46794.

Any updates on this one - is it ready for us?

Allan

 

 
Nicolai Pedersen
Reply

Hi Allan

I have a changeset for code review at my desk, been to busy... Just looked it through and have send it on for CR2 and testing.

Sorry about the delay.

BR Nicolai

 
Rui Silva
Reply

Any news on this?

I'm trying to delete pages using the API and no success either.

I tried:

    var pageService = new PageService();

    pageService.DeletePage(331);

 

or:

    var pageService = new PageService();

    var page = pageService.GetPage(331);

    pageService.MoveToBin(page);

 

or even:

    var pageService = new PageService();

    var page = pageService.GetPage(331);

 

    using (var bin = new Dynamicweb.SystemTools.RecycleBin.RecycleBin())

    {

        pageService.MoveToExistingBin(page, bin.UnitID);

    }

 

 

All of these return Exception from Dynamicweb.

 
Martin Vang
Martin Vang
Reply

Hi Rui,

It would have helped alot if you also posted the exception(s)...

The only thing I can think of, at the top of my head, would be to try to enable the MSDTC service on the server hosting Dynamicweb.

BR

Martin

 
Rui Silva
Reply

Hi Martin,

The exceptions are:

1-

Dynamicweb.SystemTools.RecycleBin.RecycleBinException: Primary item must have a value before committing
   at Dynamicweb.SystemTools.RecycleBin.RecycleBin.Commit()
   at Dynamicweb.SystemTools.RecycleBin.RecycleBin.Dispose(Boolean disposing)
   at Dynamicweb.SystemTools.RecycleBin.RecycleBin.Dispose()
   at Dynamicweb.Content.PageService.MoveToBin(Page obj)
   at Dynamicweb.Content.PageService.DeletePage(Int32 pageId)
   at CompiledRazorTemplates.Dynamic.fcddebdaabfbbfd.Execute()
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context)
   at RazorEngine.Templating.TemplateService.Run(ITemplate template, DynamicViewBag viewBag)
   at RazorEngine.Templating.TemplateService.Parse(String razorTemplate, Object model, DynamicViewBag viewBag, String cacheName)
   at RazorEngine.Razor.Parse[T](String razorTemplate, T model, String cacheName)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

 

2-

Dynamicweb.SystemTools.RecycleBin.RecycleBinException: Primary item must have a value before committing
   at Dynamicweb.SystemTools.RecycleBin.RecycleBin.Commit()
   at Dynamicweb.SystemTools.RecycleBin.RecycleBin.Dispose(Boolean disposing)
   at Dynamicweb.SystemTools.RecycleBin.RecycleBin.Dispose()
   at Dynamicweb.Content.PageService.MoveToBin(Page obj)
   at CompiledRazorTemplates.Dynamic.bcdceaebe.Execute()
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context)
   at RazorEngine.Templating.TemplateService.Run(ITemplate template, DynamicViewBag viewBag)
   at RazorEngine.Templating.TemplateService.Parse(String razorTemplate, Object model, DynamicViewBag viewBag, String cacheName)
   at RazorEngine.Razor.Parse[T](String razorTemplate, T model, String cacheName)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

 

3-

Dynamicweb.SystemTools.RecycleBin.RecycleBinException: Primary item must have a value before committing
   at Dynamicweb.SystemTools.RecycleBin.RecycleBin.Commit()
   at Dynamicweb.SystemTools.RecycleBin.RecycleBin.Dispose(Boolean disposing)
   at Dynamicweb.SystemTools.RecycleBin.RecycleBin.Dispose()
   at CompiledRazorTemplates.Dynamic.afcddec.Execute()
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context)
   at RazorEngine.Templating.TemplateService.Run(ITemplate template, DynamicViewBag viewBag)
   at RazorEngine.Templating.TemplateService.Parse(String razorTemplate, Object model, DynamicViewBag viewBag, String cacheName)
   at RazorEngine.Razor.Parse[T](String razorTemplate, T model, String cacheName)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

 

And I've tried a new version also:

4-

    var pageService = new PageService();
    var page = pageService.GetPage(331);

    using (var bin = new Dynamicweb.SystemTools.RecycleBin.RecycleBin())
    {
        var binIt = new Dynamicweb.SystemTools.RecycleBin.RecycleItem();
        binIt.Data = "www";
        binIt.AssemblyQualifiedName = page.GetType().ToString();
        binIt.DeletedAt = DateTime.Now;
        binIt.DeletedBy = "rui";
        binIt.Description = "hkxdbkjbdkjd";
        binIt.IsPrimary = true;
        binIt.ObjectID = page.ID.ToString();

        bin.AddItem(binIt);
        pageService.MoveToExistingBin(page, bin.UnitID);
    }

 

That returns the exception:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Content.PageService.CreateRecycleItem(Page page)
   at Dynamicweb.Content.PageService.MoveToBin(Page page, RecycleBin bin)
   at Dynamicweb.Content.PageService.MoveToExistingBin(Page obj, Guid unitId)
   at CompiledRazorTemplates.Dynamic.bcdcaaeacbf.Execute()
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context)
   at RazorEngine.Templating.TemplateService.Run(ITemplate template, DynamicViewBag viewBag)
   at RazorEngine.Templating.TemplateService.Parse(String razorTemplate, Object model, DynamicViewBag viewBag, String cacheName)
   at RazorEngine.Razor.Parse[T](String razorTemplate, T model, String cacheName)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

 

 

 
Martin Vang
Martin Vang
Reply

Here is what I was able to do:

1. Create new blank page. Find the id (701).

2. Create another new blank page. Add a paragraph and find the template for this paragraph.

3. Include relevant imports.

4. Place this code on the template: 

@using Dynamicweb.Extensibility
@using Dynamicweb.Content
@using System;
@using System.Globalization;
@using System.Linq
@using System.IO
@using Dynamicweb.Core
@using System.Web 

@GetValue("ParagraphText")
@GetValue("ParagraphModule")

@{
 var page = Dynamicweb.Services.Pages.GetPage(701);
 Dynamicweb.Services.Pages.DeletePage(701);
}

This code can be executed multiple times in a row without exceptions. First time it is run, the page gets moved to the recycle bin.

 

Can you post what you did? And can you also try with a new page where you havnt experimented quite as much?

BR

Martin

 
Claus Kølbæk
Claus Kølbæk
Reply

Did you ever find a solution to this? I am hitting the same: 

Dynamicweb.SystemTools.RecycleBin.RecycleBinException: Primary item must have a value before committing
 
Nicolai Pedersen
Reply

From where and how?

Custom code?

 
Claus Kølbæk
Claus Kølbæk
Reply

Well similar to what Rui have posted earlier.

I got a page that when loaded checks for old pages, news and such, and either moves them into certain folders (Dynamicweb.Services.Pages.Move(page.ID, areaId, folderId) <- works fine. but if I instead use Dynamicweb.Services.Pages.DeletePage(page.ID), I get the before mentioned error - I also looked at page.Delete(), but it seems to be doing something completely different.

I tried creating a new page, and just typed its ID manually, but results in same error, all the pages ofc. have an itemtype aswell, I haven't tested with a simple page.

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply
This post has been marked as an answer

Hi all,

Actually, the issue was fixed by #46794 on DW95 only, 94 version will be fixed by TFS 55692 new created and will be provided with nearest DW94 hotfix. Thanks.

BR, Oleg QA 

Votes for this answer: 2

 

You must be logged in to post in the forum