Microsoft Content Management Server - NullReferenceException when creating a connected posting

This is Interesting: Free IT Magazines  
Home > Archive > Microsoft Content Management Server > November 2004 > NullReferenceException when creating a connected posting





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author NullReferenceException when creating a connected posting
Daniel Graversen

2004-11-26, 5:49 pm

Hi,

I have tried to use the following code snippet to create a posting.
When copying some templates I get the following error:
object.System.NullReferenceException: Object reference not set to an
instance of an object. at
Microsoft.ContentManagement.Publishing.Channel.CreateConnectedPosting(Template
sourceTemplate, Posting existingPosting)

The user is administrator in CMS. The page when the error is send. I
get the same error when creating a copy of the page.

Is there a work around for the problem.

Regards
Daniel Graversen

CmsApplicationContext context = new CmsApplicationContext();
context. AuthenticateAsUser(user,pass,PublishingM
ode.Update);
Channel cTo =(Channel)
context.Searches.GetByPath("/channels/www.dgr.dk/da/servicemenu/");
Posting p= (Posting)context.Searches.GetByPath("/channels/www.dgr.dk/da/menu/test/daniel4");
if(cTo!=null && p!=null && p.Template!=null)
{
try
{
if(cTo.CanCreatePostings)
{
cTo.CreateConnectedPosting(p.Template,p);
context.CommitAll();
return "OK";
}
else
{return "no rigths to create posting";}
}
catch(Exception e){
context.CommitAll(); return e.Message + e.ToString();}
}
}
Stefan [MSFT]

2004-11-26, 5:49 pm

Hi Daniel,

one of the objects passed to the function seems to be null.
Either the sourceTemplate or the existingPosting.

Please debug the code and check this.

Cheers,
Stefan


"Daniel Graversen" <dgraversen@gmail.com> wrote in message
news:3717827c.0411260707.2258629f@posting.google.com...
> Hi,
>
> I have tried to use the following code snippet to create a posting.
> When copying some templates I get the following error:
> object.System.NullReferenceException: Object reference not set to an
> instance of an object. at
>

Microsoft.ContentManagement.Publishing.Channel.CreateConnectedPosting(Templa
te
> sourceTemplate, Posting existingPosting)
>
> The user is administrator in CMS. The page when the error is send. I
> get the same error when creating a copy of the page.
>
> Is there a work around for the problem.
>
> Regards
> Daniel Graversen
>
> CmsApplicationContext context = new CmsApplicationContext();
> context. AuthenticateAsUser(user,pass,PublishingM
ode.Update);
> Channel cTo =(Channel)
> context.Searches.GetByPath("/channels/www.dgr.dk/da/servicemenu/");
> Posting p=

(Posting)context.Searches.GetByPath("/channels/www.dgr.dk/da/menu/test/danie
l4");
> if(cTo!=null && p!=null && p.Template!=null)
> {
> try
> {
> if(cTo.CanCreatePostings)
> {
> cTo.CreateConnectedPosting(p.Template,p);
> context.CommitAll();
> return "OK";
> }
> else
> {return "no rigths to create posting";}
> }
> catch(Exception e){
> context.CommitAll(); return e.Message + e.ToString();}
> }
> }



Daniel Graversen

2004-11-29, 2:47 am

If I insert null in both template and/or for the posting, I get a
message that the posting and template cannot be null. I have also
added the test for if the template or positng in null, then i do not
create the copy.

It is only some postings which has the problem. Can it be something
with the templates the problem exits. Unfortantly the pages this
problem exits on is our normal content pages. So fair my workaround
has been to catch the NullReferenceException and get the posting just
created.

/daniel

"Stefan [MSFT]" <stefang@online.microsoft.com> wrote in message news:<ecIbfo80EHA.304@TK2MSFTNGP11.phx.gbl>...[vbcol=seagreen]
> Hi Daniel,
>
> one of the objects passed to the function seems to be null.
> Either the sourceTemplate or the existingPosting.
>
> Please debug the code and check this.
>
> Cheers,
> Stefan
>
>
> "Daniel Graversen" <dgraversen@gmail.com> wrote in message
> news:3717827c.0411260707.2258629f@posting.google.com...
> Microsoft.ContentManagement.Publishing.Channel.CreateConnectedPosting(Templa
> te
> (Posting)context.Searches.GetByPath("/channels/www.dgr.dk/da/menu/test/danie
> l4");
Stefan [MSFT]

2004-11-29, 7:50 am

Hi Daniel,

that sounds strange. Might be a database inconsistancy.
Please open a support case to get this analyzed.

Cheers
Stefan.

"Daniel Graversen" <dgraversen@gmail.com> wrote in message
news:3717827c.0411290035.683b84f@posting.google.com...
> If I insert null in both template and/or for the posting, I get a
> message that the posting and template cannot be null. I have also
> added the test for if the template or positng in null, then i do not
> create the copy.
>
> It is only some postings which has the problem. Can it be something
> with the templates the problem exits. Unfortantly the pages this
> problem exits on is our normal content pages. So fair my workaround
> has been to catch the NullReferenceException and get the posting just
> created.
>
> /daniel
>
> "Stefan [MSFT]" <stefang@online.microsoft.com> wrote in message

news:<ecIbfo80EHA.304@TK2MSFTNGP11.phx.gbl>...[vbcol=seagreen]
Microsoft.ContentManagement.Publishing.Channel. CreateConnectedPosting(Templa[vbcol=seag
reen]
(Posting)context.Searches.GetByPath("/channels/www.dgr.dk/da/menu/test/danie[vbcol=seagreen]


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com