0

I am trying to use an ASPX page to publish my master database to the web database.

The page contains this code:

PublishManager.Republish(Sitecore.Client.ContentDatabase, new Database[] { web }, LanguageManager.GetLanguages(master).ToArray(), Sitecore.Context.Language);

At compile time, an error is thrown saying:

Compiler Error Message: CS0434: The namespace 'Sitecore.Client' in '...\Sitecore.Client.LicenseOptions.DLL' conflicts with the type 'Sitecore.Client' in '...\Sitecore.Kernel.DLL'

And later in the error, there is:

Publish.aspx(27,56): error CS0234: The type or namespace name 'ContentDatabase' does not exist in the namespace 'Sitecore.Client' (are you missing an assembly reference?)

I know that the Sitecore.Kernel assembly contains the property used in the code above:

namespace Sitecore
{
    public static Database ContentDatabase
    {
        get
        {
            ...
        }
    }
}

I have looked online and tried a few things that did not help:

  1. Add the Sitecore.Kernel assembly in a web.config file. Maybe I did not add it the correct way. I do not know.
  2. Change the above code to specifically tell the compiler I want the "Client" static class reference with:

    var sitecoreClient = Sitecore.Client;
    PublishManager.Republish(sitecoreClient.ContentDatabase, new Database[] { web }, LanguageManager.GetLanguages(master).ToArray(), Sitecore.Context.Language);
    
  3. Add a namespace reference to "Sitecore"

    <%@ Import Namespace="Sitecore" %>
    

I am out of ideas and I do not understand how to resolve this error. I am reaching for your help. How would you solve this conflict?

Thanks

2
  • You are publishing from Master to Web? If yes, why not use master database instead of ContentDatabase. Something like this: PublishManager.Republish(master, new Database[] { web }, LanguageManager.GetLanguages(master).ToArray(), Sitecore.Context.Language); Commented Mar 26, 2018 at 10:48
  • That makes perfect sense and it works. Thanks for the idea! I somehow tried to make the code work as written by its author. Commented Mar 26, 2018 at 10:54

1 Answer 1

3

Since you are publishing from master to web, instead of using the ContentDatabase you can use master database directly.

From the code you shared:

public void Page_Load(object sender, EventArgs e)
{
  Sitecore.Context.SetActiveSite("shell");
  using (new SecurityDisabler())
  {
      DateTime publishDate = DateTime.Now;
      Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
      Sitecore.Data.Database web = Sitecore.Configuration.Factory.GetDatabase("web");
      PublishManager.Republish(Sitecore.Client.ContentDatabase, new Database[] { web }, LanguageManager.GetLanguages(master).ToArray(), Sitecore.Context.Language);
  }
}

Just change the line for Republish Method to

PublishManager.Republish(master, new Database[] { web }, LanguageManager.GetLanguages(master).ToArray(), Sitecore.Context.Language);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.