Monday, December 14, 2015

Sitecore MVC: Static rendering issue on layout

MVC is not my best strength, so I'm not sure if this was just one of those easy errors where "you should just know better", but I wasn't able to find much about this error online.

"Could not locate item containing model definition. Model path: My.Namespace.WebsiteModel"

I was creating a rather simple rendering to put in the footer of my layout, that would grab a single line text from the root item of my website. I referenced the rendering using the following code...

@Html.Sitecore().ViewRendering("~/Areas/Views/MyRendering.cshtml", new { Model = new WebsiteModel() });

Which gave me the above error. It sounds like it was looking for a Model item inside of Sitecore. But since this rendering is being used statically, I shouldn't have to create anything in Sitecore for it to work.

The following code ended up working...

@{ Html.RenderPartial("~/Areas/Views/MyRendering.cshtml", new WebsiteModel()); }
My homework now is to dig into @Html.Sitecore().ViewRendering() and see what exactly it's trying to do under the covers. I'm guessing it's more meant to be used with a Sitecore rendering item, and since I was trying to use a custom Model, it was looking for the Model item that would exist if it *was* a Sitecore item.

Wednesday, October 7, 2015

Sitecore Session State DB and On-Premise MongoDB

If you follow Sitecore's official documentation about setting up a Private Session State Database, you may notice the first "Note" at the top of the article...


Currently, among the developers I've talked to, the consensus is that MongoDB doesn't perform as well as SQL for Session State. Does this mean your stuck using MongoDB as your session store?

It seems the answer to that is "no". You are officially allowed to use whichever one you want. Sitecore just hasn't gotten around to updating their docs yet.



It took me a minute to find this, so I figured I'd repeat it and make it a little more visible until the documentation has been fixed.

Tuesday, September 22, 2015

Sitecore 8: Toggle CD Configuration Files Powershell Script

As part of Sitecore's official Configuring a CD Server, there are several configuration files and dlls that need to be disabled. This can get tedious to do if you are setting up several CD servers, or if you ever need to revert back to a CM configuration.

This powershell script should make this less time consuming: CDConfiguration.ps1

The script has 3 parameters when you run it...

  1. The folder path of your Sitecore instance's \Website (Ex: "D:\Sitecore\Dev-CD-SC8\Website\")
  2. If you are configuring a CM or a CD server.
  3. If you are using Lucene or Solr index configurations.
It will crawl through your \Include folder, and toggle the configuration files listed in the URL above. 

There are also 2 specific behaviors of the script to be aware of...
  1. It will move your SwitchMasterToWeb to a folder \zzzMustBeLast. Read more here as to the reasons why.
  2. If the configuration file exists in both an enabled and disabled state (ie: files xxx.config and xxx.config.disabled both exist), running the script with the CD parameter will assume the enabled is the most recent, and will overwrite the disabled file.
This script is useful for when you already have an instance setup and you just need to toggle the configuration files back and forth.

If you are setting up a brand new CD server, go check out Patrick Perrone's post for a PowerShell Sitecore Install Script to automate the entire process.

Thursday, July 30, 2015

Hedgehog TDS 5.1.0.9 and Sitecore 8 Update 3

Older versions of TDS have issues with Sitecore 8 Update 3, and they can manifest in a few different ways.

When installing a package that was generated using an older version of TDS, you might encounter an error about the following error...

Exception Could not find file 'C:\Inetpub\wwwroot\GasTest\Website\_DEV\DeployedItems.xml'.

In the installation screen on the Update Installation Wizard it would look like...


Or on the results screen...

Also, when you are using Visual Studios or a TFS build server to generate the package, the build might fail with the very descriptive error...

C:\Program Files (x86)\MSBuild\HedgehogDevelopment\SitecoreProject\v9.0\HedgehogDevelopment.SitecoreProject.targets (165): The package builder failed. Please see the build output log for more details.
Digging into the logs would give you the stack trace...

Building .\bin\TestCM-SC8\..\Package_TestCM-SC8\TDS.Master.scitems.update
Inner Exception Object reference not set to an instance of an object.(System.NullReferenceException):
at Sitecore.Update.Utils.ConfigurationUtils.GetConfiguration(ConfigReader reader)
at Sitecore.Update.Utils.ConfigurationUtils.GetConfigNodes(String xpath, ConfigReader reader)
at Sitecore.Update.Configuration.Factory.ReloadSettings()
at Sitecore.Update.Commands.BaseFileCommand.Serialize(XmlWriter writer, SerializationContext context)
at Sitecore.Update.Commands.SerializationCommandFactory.SerializeCommand(ICommand command, XmlWriter writer, SerializationContext context)
at Sitecore.Update.Installer.CommandToEntryConverter.ConvertFileOperationCommand(BaseFileCommand entry, Stream file)
at Sitecore.Update.Installer.CommandToEntryConverter.Convert(ICommand entry)
at Sitecore.Update.Installer.CommandToEntryConverter.InternalConvert(ICommand entry, IProcessingContext context)
at Sitecore.Install.Framework.BaseConverter`1.Convert(T entry, IProcessingContext context)
at Sitecore.Install.Framework.BaseSource`1.InternalSink.Put(T entry)
at Sitecore.Install.Framework.FilteringSink`1.Put(T entry)
at Sitecore.Update.Installer.CommandSource.InternalPopulate(ISink`1 sink)
at Sitecore.Install.Framework.BaseSource`1.Populate(ISink`1 sink)
at Sitecore.Install.PackageProject.InternalPopulate(ISink`1 sink)
at Sitecore.Install.Framework.BaseSource`1.Populate(ISink`1 sink)
at Sitecore.Install.Utils.EntrySorter.Populate(ISink`1 sink)
at Sitecore.Install.PackageGenerator.GeneratePackage(PackageProject solution, ISink`1 writer)
at Sitecore.Update.Engine.PackageGenerator.GeneratePackage(DiffInfo diff, String licenseFile, String outputPath)
Exception Cannot generate package: Object reference not set to an instance of an object.(System.Exception):
at Sitecore.Update.Engine.PackageGenerator.GeneratePackage(DiffInfo diff, String licenseFile, String outputPath)
at HedgehogDevelopment.SitecoreProject.PackageBuilder.PackageBuilder.g(g ?)
at HedgehogDevelopment.SitecoreProject.PackageBuilder.l.g(String[] ?)
5>C:\Program Files (x86)\MSBuild\HedgehogDevelopment\SitecoreProject\v9.0\HedgehogDevelopment.SitecoreProject.targets(165,5): error : The package builder failed. Please see the build output log for more details.
Fixing this error is as easy as downloading the latest version of TDS. This issue was fixed as of 5.1.0.9. More specifics about this can be found in the following links...




Wednesday, July 1, 2015

Sitecore 8 update 3, CD Servers and Index sitecore_list_index

I recently completed an upgrade to Sitecore 8 update 3. I ran into some issues after configuring the CD server following the recommended Sitecore documentation...

After configuring the CD server, I was getting numerous errors in the log file about "Index sitecore_list_index was not found".



It turns out that the sitecore_list_index should not actually be deleted from the CD, yet the standard SwitchMasterToWeb.config was doing so.

Support was kind enough to provide me with an updated SwitchMasterToWeb.config, which fixed the issue. I'm not sure if their official one has been changed yet, so I'm making the one they gave me available here for now.

SwitchMasterToWeb.config