U4-7642 - Legacy membertype object throws error when retrieving property types

Created by Richard Soeteman 04 Jan 2016, 16:14:01 Updated by Shannon Deminick 26 Jan 2016, 10:11:41

CMSImport uses the legacy MemberType class to get membertype properties. This is because I want to support V6 also.. This worked fine until 7.4 beta.

The following codesnippet gets the membertype and tries to get the propertytypes. var ct = MemberType.GetByAlias("Member"); var pt = ct.PropertyTypes;

In Umbraco 7.4 beta a YSOD is thrown instead of getting the PropertyTypes using ct.PropertyTypes. Hope this can be fixed in final release.

Comments

Sebastiaan Janssen 04 Jan 2016, 16:23:33

What's the YSOD please? Seems to work here.


Simon Steed 04 Jan 2016, 16:43:50

The error I got that triggered it was when doing a new import for CMS Import:

2016-01-03 23:18:40,944 [P6036/D17/T117] ERROR CMSImport.Controls.CMSImport - CMSImport:Error during load of wizard System.NullReferenceException: Object reference not set to an instance of an object. at Umbraco.Core.Cache.HttpRuntimeCacheProvider.GetCacheItem(String cacheKey, Func1 getCacheItem, Nullable1 timeout, Boolean isSliding, CacheItemPriority priority, CacheItemRemovedCallback removedCallback, CacheDependency dependency) at Umbraco.Core.Cache.HttpRuntimeCacheProvider.GetCacheItem(String cacheKey, Func1 getCacheItem, Nullable1 timeout, Boolean isSliding, CacheItemPriority priority, CacheItemRemovedCallback removedCallback, String[] dependentFiles) at Umbraco.Core.Cache.CacheProviderExtensions.GetCacheItem[T](IRuntimeCacheProvider provider, String cacheKey, Func1 getCacheItem, Nullable1 timeout, Boolean isSliding, CacheItemPriority priority, CacheItemRemovedCallback removedCallback, String[] dependentFiles) at Umbraco.Core.CacheHelper.GetCacheItem[TT](String cacheKey, TimeSpan timeout, Func1 getCacheItem) at umbraco.cms.businesslogic.ContentType.get_PropertyTypes() at CMSImportLibrary.Repository.Property.PropertyRepository.GetAllMemberProperties(String memberTypeAlias) at CMSImportLibrary.Repository.Member.Model.MemberType.(MemberType ) at CMSImportLibrary.Repository.Member.MemberTypeRepository.(MemberType ) at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at CMSImportLibrary.Repository.Member.MemberTypeRepository.get_All() at CMSImportLibrary.Providers.ImportProviders.Member.MemberImportProviderForm.() at CMSImportLibrary.Providers.ImportProviders.Member.MemberImportProviderForm.OnInit(EventArgs e) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.AddedControl(Control control, Int32 index) at System.Web.UI.ControlCollection.Add(Control child) at CMSImport.Controls.ImportSteps.SelectProviderOptions.() at CMSImport.Controls.ImportSteps.SelectProviderOptions.InitializeStepControl(ImportState state) at CMSImport.Controls.CMSImport.() at CMSImport.Controls.CMSImport.(Int32 ) at CMSImport.Controls.CMSImport.OnPreRender(EventArgs e)

Obviously this is returned from CMSImport, not sure what Richard has found relating to it.


Richard Soeteman 05 Jan 2016, 11:57:15

I only get the NullReference exception. Used the default starterkit of the site, weird...


Richard Soeteman 05 Jan 2016, 15:30:41

Also with Memberexport this is the real error

[NullReferenceException: Object reference not set to an instance of an object.] Umbraco.Core.Cache.HttpRuntimeCacheProvider.GetCacheItem(String cacheKey, Func1 getCacheItem, Nullable1 timeout, Boolean isSliding, CacheItemPriority priority, CacheItemRemovedCallback removedCallback, CacheDependency dependency) +1047 Umbraco.Core.Cache.HttpRuntimeCacheProvider.GetCacheItem(String cacheKey, Func1 getCacheItem, Nullable1 timeout, Boolean isSliding, CacheItemPriority priority, CacheItemRemovedCallback removedCallback, String[] dependentFiles) +155 Umbraco.Core.Cache.CacheProviderExtensions.GetCacheItem(IRuntimeCacheProvider provider, String cacheKey, Func1 getCacheItem, Nullable1 timeout, Boolean isSliding, CacheItemPriority priority, CacheItemRemovedCallback removedCallback, String[] dependentFiles) +237 Umbraco.Core.CacheHelper.GetCacheItem(String cacheKey, TimeSpan timeout, Func`1 getCacheItem) +346 umbraco.cms.businesslogic.ContentType.get_PropertyTypes() +150


Shannon Deminick 25 Jan 2016, 15:30:17

@zpqrtbnk Going to assign you this issue, it should be pretty easy for you. The issue is due to changes made in revision: eb5589e0645d645eaf771797c3956ee7952eeb28 ('Remove PropertyGroup.ParentId, sanitize Property groups/types'). Specifically the problem is in umbraco.cms.businesslogic.ContentType.MasterContentTypes property in the 'get' on these lines:

var ct = ApplicationContext.Current.Services.ContentTypeService.GetContentType(Id);
m_masterContentTypes = ct.CompositionPropertyGroups.Select(x => x.Id).ToList();

in this case, ct is null, but we don't check that and an exception is thrown. I know I can do a null check here but i think you are more familiar with what is supposed to be happening with regards to these changes.


Shannon Deminick 25 Jan 2016, 15:31:07

If you don't have time just let me know and i'll come back to this mid week


Stephan 25 Jan 2016, 16:27:27

Looking into it now.


Stephan 25 Jan 2016, 16:34:17

Reproduced.


Stephan 25 Jan 2016, 16:45:57

Root cause of issue = me trying to make some sense of the "creative and diverse" code of the ContentType class and forgetting that it's a base class for content, media and member types. Using ContentTypeService.GetContentType(alias) aggressively instead of having a nice switch depending on what we actually want. What a mess. Fixing, probably by just reverting.


Stephan 25 Jan 2016, 17:18:13

Fixed with PR https://github.com/umbraco/Umbraco-CMS/pull/1052


Priority: Task - Pri 1

Type: Bug

State: Fixed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.4.0

Due in version: 7.4.0

Sprint: Sprint 7

Story Points:

Cycle: