@@ -464,6 +464,10 @@ internal class DictionaryPublishedContent : PublishedContentBase
464
464
// I'm not sure that _properties contains all properties including those without a value,
465
465
// neither that GetProperty will return a property without a value vs. null... @zpqrtbnk
466
466
467
+ // List of properties that will appear in the XML and do not match
468
+ // anything in the ContentType, so they must be ignored.
469
+ private static readonly string [ ] IgnoredKeys = { "version" , "isDoc" , "key" } ;
470
+
467
471
public DictionaryPublishedContent (
468
472
IDictionary < string , string > valueDictionary ,
469
473
Func < DictionaryPublishedContent , IPublishedContent > getParent ,
@@ -509,47 +513,36 @@ public DictionaryPublishedContent(
509
513
_contentType = PublishedContentType . Get ( PublishedItemType . Media , _documentTypeAlias ) ;
510
514
_properties = new Collection < IPublishedContentProperty > ( ) ;
511
515
516
+ //handle content type properties
517
+ //make sure we create them even if there's no value
518
+ foreach ( var propertyType in _contentType . PropertyTypes )
519
+ {
520
+ var alias = propertyType . PropertyTypeAlias ;
521
+ _keysAdded . Add ( alias ) ;
522
+ string value ;
523
+ const bool isPreviewing = false ; // false :: never preview a media
524
+ var property = valueDictionary . TryGetValue ( alias , out value ) == false
525
+ ? new XmlPublishedProperty ( propertyType , isPreviewing )
526
+ : new XmlPublishedProperty ( propertyType , isPreviewing , value ) ;
527
+ _properties . Add ( property ) ;
528
+ }
529
+
512
530
//loop through remaining values that haven't been applied
513
- foreach ( var i in valueDictionary . Where ( x => ! _keysAdded . Contains ( x . Key ) ) )
531
+ foreach ( var i in valueDictionary . Where ( x =>
532
+ _keysAdded . Contains ( x . Key ) == false // not already processed
533
+ && IgnoredKeys . Contains ( x . Key ) == false ) ) // not ignorable
514
534
{
515
- IPublishedContentProperty property ;
516
-
517
- // must ignore that one
518
- if ( i . Key == "version" || i . Key == "isDoc" ) continue ;
519
-
520
535
if ( i . Key . InvariantStartsWith ( "__" ) )
521
- {
522
- // no type for tha tone, dunno how to convert
523
- property = new PropertyResult ( i . Key , i . Value , Guid . Empty , PropertyResultType . CustomProperty ) ;
524
- }
536
+ {
537
+ // no type for that one, dunno how to convert
538
+ IPublishedContentProperty property = new PropertyResult ( i . Key , i . Value , Guid . Empty , PropertyResultType . CustomProperty ) ;
539
+ _properties . Add ( property ) ;
540
+ }
525
541
else
526
542
{
527
- // use property type to ensure proper conversion
528
- var propertyType = _contentType . GetPropertyType ( i . Key ) ;
529
-
530
- // note: this is where U4-4144 and -3665 were born
531
- //
532
- // because propertyType is null, the XmlPublishedProperty ctor will throw
533
- // it's null because i.Key is not a valid property alias for the type...
534
- // the alias is case insensitive (verified) so it means it really is not
535
- // a correct alias.
536
- //
537
- // in every cases this is after a ConvertFromXPathNavigator, so it means
538
- // that we get some properties from the XML that are not valid properties.
539
- // no idea which property. could come from the cache in library, could come
540
- // from so many places really.
541
-
542
- // workaround: just ignore that property
543
- if ( propertyType == null )
544
- {
545
- LogHelper . Warn < PublishedMediaCache > ( "Dropping property \" " + i . Key + "\" because it does not belong to the content type." ) ;
546
- continue ;
547
- }
548
-
549
- property = new XmlPublishedProperty ( propertyType , false , i . Value ) ; // false :: never preview a media
543
+ // this is a property that does not correspond to anything, ignore and log
544
+ LogHelper . Warn < PublishedMediaCache > ( "Dropping property \" " + i . Key + "\" because it does not belong to the content type." ) ;
550
545
}
551
-
552
- _properties . Add ( property ) ;
553
546
}
554
547
}
555
548
0 commit comments