Copied to clipboard

Flag this post as spam?

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


  • Jesus Mogollon 6 posts 77 karma points
    May 31, 2017 @ 14:22
    Jesus Mogollon
    0

    Unable to load MetaSettings after model build

    I'm using umbraco v7.6.2.

    I have managed to fix the cast errors along with other errors in the extension classes of blog and portfolio.

    Now I facing a different issue that I hope someone can help.

    After adding a property and do a 'Generate Model' the following line in the siteTemplate.cshtml returns the following error:

    Method not found: 'System.Object Umbraco.Web.PublishedContentModels.ConfigGlobalSettings.get_PolicyIfOgtagEmpty()'.
    
    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.MissingMethodException: Method not found: 'System.Object Umbraco.Web.PublishedContentModels.ConfigGlobalSettings.get_PolicyIfOgtagEmpty()'.
    

    This error is throw in the following line:

    MetaSettings settings = configPage.GetMetaSettings();

    A little more details on it:

    [MissingMethodException: Method not found: 'System.Object Umbraco.Web.PublishedContentModels.ConfigGlobalSettings.get_PolicyIfOgtagEmpty()'.]
       DotSee.PageMetas.ConfigNodeExtensions.GetMetaSettingsImpl(ConfigGlobalSettings configPage) +0
       DotSee.PageMetas.<>c__DisplayClass0_0.<GetMetaSettings>b__0() +8
       Umbraco.Core.Cache.<>c__DisplayClass1.<GetSafeLazy>b__0() +31
    

    I'm trying to get to the source of the problem and fix it, but I'm afraid that this error may be in the code inside the 'DotSee.PageMetas.dll', which I can't find the source.

    Anyone with any pointers or hints where to look?

    I already checked the generated model for ConfigGlobalSettings (ConfigGlobalSettings.generated.cs in App_Data\Models) and the property 'PolicyIfOgtagEmpty' exist there, so I don't know where else I can check...

    Thanks in advance

  • Sotiris Filippidis 197 posts 1006 karma points
    May 31, 2017 @ 16:01
    Sotiris Filippidis
    0

    I feel I must apologize for not being able to answer for quite a few weeks now, due to an insane workload.

    PageMetas is a reusable library that I've been using in quite a few sites. What causes the error is here:

     private static MetaSettings GetMetaSettingsImpl(ConfigGlobalSettings configPage)
            {
                string titlePolicy = (configPage.PolicyIfOgtagEmpty!=null)? umbraco.library.GetPreValueAsString((int)configPage.PolicyIfOgtagEmpty) : "Home Page";
    

    But this one is in turn called by this:

      public static MetaSettings GetMetaSettings(this ConfigGlobalSettings configPage)
            {
                return (MetaSettings)ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem(string.Concat("MetaSettings_", configPage.Id.ToString()), () => GetMetaSettingsImpl(configPage));
            }
    

    So what happens is that either something is going on with the runtime cache, or that you are no longer referencing Umbraco.Web.PublishedContentModels (since you are talking about an app_data model build).

    Sorry I can't help more at the moment, as I said, crazy workload :(

  • Jesus Mogollon 6 posts 77 karma points
    May 31, 2017 @ 16:55
    Jesus Mogollon
    0

    Thanks a lot Sotiris, I will deep dive into that.

  • Sotiris Filippidis 197 posts 1006 karma points
    May 31, 2017 @ 16:59
    Sotiris Filippidis
    0

    Ah! Now that I see it, it just might be a cast error too. If there's been a new property value converter for radio button lists, then this might be it. I haven't tested PageMetas in 7.6 (nor the theme, for that matter) so I'm not sure yet.

  • Jesus Mogollon 6 posts 77 karma points
    May 31, 2017 @ 17:11
    Jesus Mogollon
    0

    By the way I have done some changes for it to work on 7.6.2, if you want it to check it out just let me know.

  • Jesus Mogollon 6 posts 77 karma points
    May 31, 2017 @ 17:10
    Jesus Mogollon
    0

    I think it is.

    I will try to manually populate the setting object from cache with one of the calls that you have on the previous post.

    If you can post the full GetMetaSettings function will be great.

    Thanks anyway

  • Sotiris Filippidis 197 posts 1006 karma points
    May 31, 2017 @ 17:15
    Sotiris Filippidis
    0

    Thanks, I know I should change it for 7.6 already, but tons of work, tons!

    Here's the full code for the whole file containing the GetMetaSettings function:

    using Umbraco.Core;
    using Umbraco.Web.PublishedContentModels;
    namespace DotSee.PageMetas
    {
        public static class ConfigNodeExtensions
        {
            public static MetaSettings GetMetaSettings(this ConfigGlobalSettings configPage)
            {
                return (MetaSettings)ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem(string.Concat("MetaSettings_", configPage.Id.ToString()), () => GetMetaSettingsImpl(configPage));
            }
            private static MetaSettings GetMetaSettingsImpl(ConfigGlobalSettings configPage)
            {
                string titlePolicy = (configPage.PolicyIfOgtagEmpty!=null)? umbraco.library.GetPreValueAsString((int)configPage.PolicyIfOgtagEmpty) : "Home Page";
                string descriptionPolicy = (configPage.PolicyIfOgdescriptionTagEmpty != null) ? umbraco.library.GetPreValueAsString((int)configPage.PolicyIfOgdescriptionTagEmpty) : "Home Page";
                string imagePolicy = (configPage.PolicyIfOgimageTagEmpty != null) ? umbraco.library.GetPreValueAsString((int)configPage.PolicyIfOgimageTagEmpty) : "Home Page";
                return new MetaSettings(
                    titlePolicy: GetPolicy(titlePolicy),
                    descriptionPolicy: GetPolicy(descriptionPolicy),
                    imagePolicy: GetPolicy(imagePolicy),
                    fieldsForTitle: configPage.FieldsForOgtitle,
                    fieldsForDescription: configPage.FieldsForOgdescription,
                    fieldsForImage: configPage.FieldsForOgimage,
                    typeIfEmpty: configPage.TypeIfOgtagEmpty,
                    copyMetaTitleFromOgIfEmpty: configPage.CopyMetaTitleFromOgIfEmpty,
                    copyMetaDescriptionFromOgIfEmpty: configPage.CopyMetaDescriptionFromOgIfEmpty,
                    siteName: configPage.SiteName,
                    addSiteNameToBrowserTitle: configPage.AddSuffix
                    );
            }
            private static GlobalPolicyIfEmpty GetPolicy(string policyLiteral)
            {
                GlobalPolicyIfEmpty policy = GlobalPolicyIfEmpty.HomePage;
                switch (policyLiteral)
                {
                    case "Home Page":
                        policy = GlobalPolicyIfEmpty.HomePage;
                        break;
                    case "Infer from Other Fields":
                        policy = GlobalPolicyIfEmpty.PageFields;
                        break;
                    case "Leave Empty":
                        policy = GlobalPolicyIfEmpty.LeaveEmpty;
                        break;
                    default:
                        policy = GlobalPolicyIfEmpty.HomePage;
                        break;
                }
                return policy;
            }
        }
    
    }
    
  • Jesus Mogollon 6 posts 77 karma points
    May 31, 2017 @ 17:22
    Jesus Mogollon
    0

    Thanks a lot man, you are a saver.

    Happy coding!

  • Jesus Mogollon 6 posts 77 karma points
    May 31, 2017 @ 17:50
    Jesus Mogollon
    1

    Thanks again Sotiris.

    Here is the code that I used:

    using Umbraco.Core;
    using Umbraco.Web.PublishedContentModels;
    
    namespace DotSee.PageMetas
    {
        public static class ConfigNodeExtensions
        {
            public static MetaSettings GetMetaSettingsCustom(this ConfigGlobalSettings configPage)
            {
                return (MetaSettings)ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem(string.Concat("MetaSettings_", configPage.Id.ToString()), () => GetMetaSettingsImplCustom(configPage));
            }
    
            private static MetaSettings GetMetaSettingsImplCustom(ConfigGlobalSettings configPage)
            {
                return new MetaSettings(
                    titlePolicy: (GlobalPolicyIfEmpty)configPage.PolicyIfOgtagEmpty,
                    descriptionPolicy: (GlobalPolicyIfEmpty)configPage.PolicyIfOgdescriptionTagEmpty,
                    imagePolicy: (GlobalPolicyIfEmpty)configPage.PolicyIfOgimageTagEmpty,
                    fieldsForTitle: configPage.FieldsForOgtitle,
                    fieldsForDescription: configPage.FieldsForOgdescription,
                    fieldsForImage: configPage.FieldsForOgimage,
                    typeIfEmpty: configPage.TypeIfOgtagEmpty,
                    copyMetaTitleFromOgIfEmpty: configPage.CopyMetaTitleFromOgIfEmpty,
                    copyMetaDescriptionFromOgIfEmpty: configPage.CopyMetaDescriptionFromOgIfEmpty,
                    siteName: configPage.SiteName,
                    addSiteNameToBrowserTitle: configPage.AddSuffix
                    );
            }
        }
    
    }
    

    Also change the following line in the siteTemplate.cshtml to:

    MetaSettings settings = configPage.GetMetaSettingsCustom();
    

    The issue was the type conversion, the properties are no longer string these are now int.

  • Paul Taylor 8 posts 78 karma points
    Sep 13, 2017 @ 08:34
    Paul Taylor
    0

    Hey Jesus

    How did you go about fixing the errors in Blog and Portfolio helpers in 7.6?

    I am using 7.6.6 and hit the same issues when adding a new Document Type property, and then generating models.

    I have fixed a couple, but the others I have commented out for now until I can look at them properly (mainly the Category CSV helper methods).

    I am going to implement your custom meta helper above as I am now hitting this issue.

    Thanks

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft