Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nuno Inácio 9 posts 59 karma points
    Apr 07, 2016 @ 22:56
    Nuno InĂ¡cio
    0

    Exception from ContentTypeService.GetAllContentTypes()

    Hi everyone!

    I'm having an exception on my code related with the usage of ContentTypeService.GetAllContentTypes().

    I'm using this line of code on every single page request:

    var contentList = Umbraco.Core.ApplicationContext.Current.Services.ContentTypeService.GetAllContentTypes();

    foreach (ContentType ct in contentList) { if (null != ct && !String.IsNullOrEmpty(ct.Alias) && !String.IsNullOrEmpty(ct.Name) && ct.Alias.Equals(currentNode.NodeTypeAlias)) { switch (ct.Name) { case "Faq Article": document_NodeType = "Faq"; break;

                    case "External Page":
                        document_NodeType = "External";
                        break;
    
                    case "Join Form Page":
                        document_NodeType = "Form";
                        break;
    
                    case "News Page":
                        document_NodeType = "News";
                        break;
    
                    case "Product Page":
                        document_NodeType = "Product";
                        break;
    
                    case "Promotion Page":
                        document_NodeType = "Promotion";
                        break;
    
                    case "Service Page":
                        document_NodeType = "Services";
                        break;
    
                    case "Support Page":
                        document_NodeType = "Support";
                        break;
    
                    case "Static Page":
                        document_NodeType = "Support";
                        break;
    
                    case "Video Page":
                        document_NodeType = "Video";
                        break;
                }
    
                break;
            }
        }
    

    I've noticed that my CPU stucks at 100% of usage and I get the following exception:

    2016-04-07 11:46:06,548 [60] WARN umbraco.macro - [Thread 82] Error loading MacroEngine script (file: /Common Settings/WebsiteMetadata.cshtml, Type: ''. Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object. at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at Umbraco.Core.Models.EntityBase.TracksChangesEntityBase.OnPropertyChanged(PropertyInfo propertyInfo) at Umbraco.Core.Models.EntityBase.TracksChangesEntityBase.SetPropertyValueAndDetectChanges[T](Func2 setValue, T value, PropertyInfo propertySelector) at Umbraco.Core.Models.ContentType.setAllowedTemplates(IEnumerable1 value) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index) at Umbraco.Core.Models.DeepCloneHelper.DeepCloneRefProperties(IDeepCloneable input, IDeepCloneable output) at Umbraco.Core.Models.ContentTypeCompositionBase.DeepClone() at Umbraco.Core.Models.ContentTypeCompositionBase.<DeepClone>b__2f(IContentTypeComposition x) at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Umbraco.Core.Models.ContentTypeCompositionBase.DeepClone() at Umbraco.Core.Models.ContentTypeCompositionBase.<DeepClone>b__2f(IContentTypeComposition x) at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Umbraco.Core.Models.ContentTypeCompositionBase.DeepClone() at Umbraco.Core.Models.ContentTypeCompositionBase.<DeepClone>b__2f(IContentTypeComposition x) at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Umbraco.Core.Models.ContentTypeCompositionBase.DeepClone() at Umbraco.Core.Persistence.Caching.RuntimeCacheProvider.GetById(Type type, Guid id) at Umbraco.Core.Persistence.Repositories.RepositoryBase2.TryGetFromCache(TId id) at Umbraco.Core.Persistence.Repositories.RepositoryBase2.Get(TId id) at Umbraco.Core.Persistence.Repositories.ContentTypeRepository.<PerformGetAll>d__2.MoveNext() at System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at Umbraco.Core.Persistence.Repositories.RepositoryBase2.GetAll(TId[] ids) at Umbraco.Core.Services.ContentTypeService.GetAllContentTypes(Int32[] ids) at ASP.PagemacroScriptsCommonSettingsWebsiteMetadata_cshtml.Execute() in \httpddocs\MacroScripts\Common Settings\WebsiteMetadata.cshtml:line 136 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.WebPages.WebPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage) at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage) at umbraco.macro.loadMacroScript(MacroModel macro) at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)

    Did anyone get this behavior previously? Am I doing something wrong?

    Thanks in advance.

Please Sign in or register to post replies

Write your reply to:

Draft