Invalid Cast
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > Microsoft Content Management Server > Invalid Cast




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Invalid Cast  
Tom


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:27 PM

My CMS application compiles just fine with this line.  Note:  I had to cast
the result as a Posting object.

Posting PostingItem;
PostingItem =
(Posting)CmsHttpContext.Current.Searches.GetByPath(SubChannelItem.Path +
SubChannelItem.DefaultPostingName);


But when I run my application, I get the following error:

Specified cast is not valid

Can anyone assist?

Note:  I don't have a posting in the channel as of yet.  My next line of
code checks to see if its null but I'm not getting that far.



if (PostingItem != null)

Thanks

Tom







[ Post a follow-up to this message ]



    Re: Invalid Cast  
Stefan [MSFT]


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:27 PM

Hi Tom,

first of all: you should use the "as" cast:

PostingItem = CmsHttpContext.Current.Searches.GetByPath(SubChannelItem.Path
+
SubChannelItem.DefaultPostingName) as Posting;

This will avoid exceptions.

The problem can occur if
a) the search returns "null" means no object with this name exists
b) a channel with the same name exists as your Default  Posting. Then you
would get a Channel object which cannot be casted to Posting.

Cheers,
Stefan



--
This posting is provided "AS IS" with no warranties, and confers no rights

New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
Check out the new book as well: Advanced MCMS development:
http://tinyurl.com/8ugwj
----------------------


"Tom" <Tom@discussions.microsoft.com> wrote in message
news:F9FD2B7D-6887-45AA-8289-0EACA32EE613@microsoft.com...
> My CMS application compiles just fine with this line.  Note:  I had to
> cast
> the result as a Posting object.
>
> Posting PostingItem;
> PostingItem =
> (Posting)CmsHttpContext.Current.Searches.GetByPath(SubChannelItem.Path +
> SubChannelItem.DefaultPostingName);
>
>
> But when I run my application, I get the following error:
>
> Specified cast is not valid
>
> Can anyone assist?
>
> Note:  I don't have a posting in the channel as of yet.  My next line of
> code checks to see if its null but I'm not getting that far.
>
>
>
> if (PostingItem != null)
>
> Thanks
>
> Tom
>
>







[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:32 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register