Tuesday, October 2, 2007

Error: The type or namespace name 'Publishing' does not exist

Here's something useful I've learned today...

I had created a custom master file and included this line:

<img runat="server" src="<% $SPUrl:~SiteCollection/Style Library/Images/~language/LocalLogo.JPG%>" alt="Logo"/>

This line had to provide a localized site logo for a MOSS 2007 site. When I tried using the master page, I got the following error:

An error occurred during the compilation of the requested file, or one of its dependencies. The type or namespace name 'Publishing' does not exist in the namespace 'Microsoft.SharePoint' (are you missing an assembly reference?)

After quite a long search (at least for such a "small" problem), I finally found the solution on Clever Workarounds. Apparently, the error was that I had used the Default.master file to start my custom page from. This masterpage doesn't support Publishing by default though (as opposed to Blueband.master for example), so you have to add these following assembly declarations to your custom master page:

<%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="PublishingVariations" TagName="VariationsLabelMenu" src="~/_controltemplates/VariationsLabelMenu.ascx" %>
<%@ Register Tagprefix="PublishingConsole" TagName="Console" src="~/_controltemplates/PublishingConsole.ascx" %>
<%@ Register TagPrefix="PublishingSiteAction" TagName="SiteActionMenu" src="~/_controltemplates/PublishingActionMenu.ascx" %>


That should do the job...

13 comments:

Anonymous said...

Thanks,

I had the same problem. Thanks to google and your blog post it's solved now.

grt,

Lieven

Tom said...

You're very welcome, I'm glad my post was of any use!

Anonymous said...

Thanks, this helped me fix my problem also.

One thing i don't understand is why this error occurred on the default.master

Tom said...

You're welcome!

As far as I can tell, this error occurs on the default.master page whenever you add something that needs the publishing namespace to work. By default, this isn't activated on the default.master though, so you need to add the import statements yourself. I don't have a clue why Microsoft hasn't included this by default though...

Vijay Kumar said...

In India, we have three word for "You" word from your language.

"AAP" : when showing respect to elder

"TUM" : used by friends and in family members

"TU" : used by elders to call youngers or when there is no respect but just want to call anybody


AND You ARE IN First Category !!!!
You Are Great !!!!

Tom said...

Thank you very much vj, I'm glad I was able to help you with my post!

Anonymous said...

Thanks,

short and helpful

Anonymous said...

Ah ha! fixed. ta

Viren said...

No I am still getting the same problem

Mehmet said...

Hi,
Where can I add this data, if I create a web part using CS 2008? There is not a master page file there.

Thanks in advance,
Mehmet

Tom said...

Hi Mehment,

I think your problem will be elsewhere, because a master page is a file that is used to be a placeholder for the layout of your SharePoint sites, but it has nothing to do with webparts. So if you get this error when you're trying to create a webpart, than there's probably something wrong with your webpart. One thing you can try is to open your web part project and add a reference to Microsoft.SharePoint.Publishing.dll, that might solve your problem.

Unknown said...

Thanks a lot Tom... one question though... ~SiteCollection/Style Library is available only for publishing enabled features?

Tom said...

You're very welcome Neevedita!

As far as I understand your question, you can only use ~SiteCollection/Style Library when you're referencing the publishing namespace, that's why you explicitly register it in your master page.