<?xml version="1.0" encoding="utf-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><language>en</language><title>Blog posts by John Frings</title> <link>https://world.optimizely.com/blogs/John-Frings/</link><description></description><ttl>60</ttl><generator>Optimizely World</generator><item> <title>PropertyData object with name &quot;FooBar&quot; already exists</title>            <link>http://fringan.blogspot.com/2012/05/propertydata-object-with-name-foobar.html</link>            <description>&lt;br /&gt;I ran into this during the weekend while I did some work from home. The site I was working on is running EPi6r2 with &lt;a href=&quot;http://pagetypebuilder.codeplex.com/&quot;&gt;PageTypeBuilder&lt;/a&gt; and I was just adding a couple of new properties for a page type when I suddenly and unexpectedly got the yellow screen of death exception message thrown a me. I couldn&#39;t access any page, nor the edit or admin modes.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Googling a little, there was some talk on &lt;a href=&quot;http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=15862&amp;amp;epslanguage=en&quot;&gt;forums&lt;/a&gt; and &lt;a href=&quot;http://andrewgunn.blogspot.se/2008/04/propertydata-object-with-name.html&quot;&gt;blogs&lt;/a&gt; about the problem being related to language handling and such but none of the things I found applied to my situation.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;...so I started tracing the origin of the exception back through &lt;a href=&quot;http://www.reflector.net/&quot;&gt;Reflector&lt;/a&gt; and ended up in EpiServer.Core.PropertyDataCollection:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;public void Add(string name, PropertyData value)&lt;br /&gt;{&lt;br /&gt;    this.InternalApproveObject(name, value);&lt;br /&gt;    if (base.BaseGet(name) != null)&lt;br /&gt;    {&lt;br /&gt;        throw new ApplicationException(&quot;PropertyData object with name \&quot;&quot; + name + &quot;\&quot; already exists&quot;);&lt;br /&gt;    }&lt;br /&gt;    value.Parent = this;&lt;br /&gt;    base.BaseAdd(name, value);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;EPi, rightfully I might add, detected that I had added more than one property with the same name. &lt;i&gt;(On a side note, I can think of a bunch of more pleasant&amp;nbsp;behaviors&amp;nbsp;to handle property doublets than to just throw an Application Exception; use the first (lowest id) and automatically remove the clones, rename the clones using a prefix or suffix, etc.). &lt;/i&gt;How could I add several properties with the same name on the same page type? To be honest I&#39;m not exactly sure but I think this is what might have happened:&lt;br /&gt;&lt;br /&gt;First off, at the time I was on a fairly slow Wifi connection, running the site locally but connecting it to a remote database over VPN. The fact that,&amp;nbsp;after compiling.&amp;nbsp;I&amp;nbsp;hit the reload button in Chrome for both the site, edit mode and admin mode in three different tabs pretty much at the same time probably also contributed since, iirc, they each run as a separate application.&amp;nbsp;Delays in contact with SQL probably enabled PTB to insert multiple copies of the same property from the different applications in question.&lt;br /&gt;&lt;br /&gt;Once I figured this out it was easy enough to manually edit out doublets from tblPageDefinition in the database and the site would work as expected again.&lt;/div&gt;</description>            <guid>http://fringan.blogspot.com/2012/05/propertydata-object-with-name-foobar.html</guid>            <pubDate>Wed, 02 May 2012 16:51:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>Programmatically adding options to EPi CMS 6 R2 drop-down list property when using PageTypeBuilder 2.0</title>            <link>http://fringan.blogspot.com/2012/02/programmatically-adding-options-to-epi.html</link>            <description>Since EPi CMS had property types with custom settings added I have found the drop-down list&amp;nbsp;(&lt;a href=&quot;http://episerver.specializedproperties.propertydropdownlist/&quot;&gt;EPiServer.SpecializedProperties.PropertyDropDownList&lt;/a&gt;) especially useful for allowing an editor to choose from a few different teaser content block appearances when creating teaser page types. The out-of-the-box approach is for an CmsAdmin or developer to manually add key-value pair type options in the CMS admin mode for the property but when using &lt;a href=&quot;http://pagetypebuilder.codeplex.com/&quot;&gt;PageTypeBuilder&lt;/a&gt; there is a nice way of &lt;a href=&quot;http://joelabrahamsson.com/entry/page-type-builder-2-preview-1-released&quot;&gt;adding settings programmatically&lt;/a&gt;:&lt;br /&gt;&lt;br /&gt;&lt;a name=&quot;more&quot;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;I implemented it in a way so that I can add a drop-down list using the attribute class PropertyDropDownListSettings like this:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;[PageTypeProperty(&lt;br /&gt;    EditCaption = &quot;Layout&quot;,&lt;br /&gt;    DefaultValue = &quot;default&quot;,&lt;br /&gt;    Required = true,&lt;br /&gt;    SortOrder = 11,&lt;br /&gt;    Type = typeof(EPiServer.SpecializedProperties.PropertyDropDownList))]&lt;br /&gt;[PropertyDropDownListSettings(&lt;br /&gt;    Settings = new string[]&lt;br /&gt;    {&lt;br /&gt;        &quot;Default|default&quot;,&lt;br /&gt;        &quot;Compact|compact&quot;,&lt;br /&gt;        &quot;Video|video&quot;,&lt;br /&gt;        &quot;RSS Feed|rss&quot;,&lt;br /&gt;        &quot;Wide|wide&quot;&lt;br /&gt;    })]&lt;br /&gt;public virtual string TeaserLayout { get; set; }&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Attribute classes only accept primitive constants and arrays of primitives as parameters and I wanted to add one to many name-value pairs of &amp;lt;string, string&amp;gt;. I settled for a string array with pipe separated pairs and some old fashioned string handling in the UpdateSettings method. I only tested this lightly so the following may be subject to update:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;using System;&lt;br /&gt;using System.Text;&lt;br /&gt;using EPiServer.Web.PropertyControls.PropertySettings;&lt;br /&gt;using PageTypeBuilder;&lt;br /&gt;&lt;br /&gt;public class PropertyDropDownListSettingsAttribute : Attribute, IUpdatePropertySettings&amp;lt;MultipleOptionsListSettings&amp;gt;&lt;br /&gt;{&lt;br /&gt;    //// { &quot;Name|value&quot;, &quot;Name|value2&quot;, &quot;Name|value3&quot; }&lt;br /&gt;    public virtual string[] Settings { get; set; }&lt;br /&gt;&lt;br /&gt;    public bool OverWriteExistingSettings&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return true;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public int GetSettingsHashCode(MultipleOptionsListSettings settings)&lt;br /&gt;    {&lt;br /&gt;        StringBuilder sb = new StringBuilder();&lt;br /&gt;&lt;br /&gt;        foreach (string optionValue in settings.ListOptions.Values)&lt;br /&gt;        {&lt;br /&gt;            sb.Append(optionValue);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        return sb.GetHashCode();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void UpdateSettings(MultipleOptionsListSettings settings)&lt;br /&gt;    {&lt;br /&gt;        if (this.Settings != null)&lt;br /&gt;        {&lt;br /&gt;            foreach (string pair in this.Settings)&lt;br /&gt;            {&lt;br /&gt;                string[] splitPair = pair.Split(&#39;|&#39;);&lt;br /&gt;&lt;br /&gt;                if (splitPair.Length &amp;gt;= 2 &amp;amp;&amp;amp;&lt;br /&gt;                    !string.IsNullOrEmpty(splitPair[0]) &amp;amp;&amp;amp;&lt;br /&gt;                    !string.IsNullOrEmpty(splitPair[1]))&lt;br /&gt;                {&lt;br /&gt;                    if (settings.ListOptions.ContainsKey(splitPair[0]))&lt;br /&gt;                    {&lt;br /&gt;                        settings.ListOptions[splitPair[0]] = splitPair[1];&lt;br /&gt;                    }&lt;br /&gt;                    else&lt;br /&gt;                    {&lt;br /&gt;                        settings.ListOptions.Add(splitPair[0], splitPair[1]);&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;As you can tell, this allows for adding new name-value pairs and updating values for existing names. It&#39;s still possible to add additional values in admin mode since UpdateSettings will not remove anything. If a name-value pair is removed in the page type definition class file, then that value must be deleted in admin mode since it will remain active until someone does so.</description>            <guid>http://fringan.blogspot.com/2012/02/programmatically-adding-options-to-epi.html</guid>            <pubDate>Tue, 21 Feb 2012 11:19:00 GMT</pubDate>           <category>Blog post</category></item></channel>
</rss>