Development

Create multilingual Dynamic Content items (including bugfixes)

If you need to create Dynamic Content Items through code, like I did a few days ago, you probably can't find any documentation or sample code. That is because there isn't any.

Daniel Plomp

December 10th, 2018

Background information

If you need to create Dynamic Content Items through code, as I did a few days ago, you probably can't find any documentation or sample code. That is because there isn't any.

And if you finally know how to create multilingual versions of Dynamic Content items, it will fail you, since there is a known bug in Sitefinity that gives you troubles.

Of course, with the great help of Sitefinity support, I could download a fix and all works fine now.

Requirements

The requirements for my little project were to import projects that had been created with an older custom module, back in the days of Sitefinity 4.x. I had to get the data out of this module and insert it into my new Dynamic Module, which is way better and easier to implement. If you still run on older versions of Sitefinity, I recommend migrating old custom modules to Dynamic Modules (if they are not TOO complex of course) and if you still run your site on Sitefinity 3.7, I also recommend to migrate to the latest version of Sitefinity.

So, I wanted to import the old data and create new Dynamic Content items with their different languages at the same time.

Solution

This is the code you need:

There unfortunately was an error that was raised every time I tried to add the English language and in particular when adding content to a field of type LString (a LongText). The error that arises is: 

Expected instance of type Telerik.Sitefinity.DynamicTypes.Model.Projects.Project
Parameter name: component
Actual value was Telerik.Sitefinity.DynamicTypes.Model.Projects.Project.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Expected instance of type Telerik.Sitefinity.DynamicTypes.Model.Projects.Project
Parameter name: component
Actual value was Telerik.Sitefinity.DynamicTypes.Model.Projects.Project.

In the end, it was approved as a bug in Sitefinity.

Bugfix

The bug will be fixed in Sitefinity 6.3. Until then, you can download this fix of the Telerik.Sitefinity.Model.dll if you need to work with multilingual versions of your Dynamic Modules.

The .dll is for version Sitefinity 6.2.4910. You have to include it in your project and then build it. Please make sure you make a backup of your original .dll  and try this solution on a backup of your project first.

All rights reserved © ZimplerApps 2018