Copied to clipboard

Flag this post as spam?

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


  • marcelh 171 posts 471 karma points
    Aug 18, 2015 @ 07:57
    marcelh
    0

    NullReferenceException on Umbraco Forms with DefaultValue for logged in member

    I'm running Umbraco 7.2.8 with Umbraco Forms 4.1.4 and receive a NullReferenceException when I use DefaultValue in a form for a logged-in member.

    Steps to reproduce:

    1. Create a new form and use the Contact form template
    2. For name or emailaddress set the DefaultValue to {member.name} or {member.email}
    3. Open the form after logging in and a NullReferenceException occurs.
    
        [NullReferenceException: Object reference not set to an instance of an object.]
        Umbraco.Core.Cache.HttpRuntimeCacheProvider.GetCacheItem(String cacheKey, Func`1 getCacheItem, Nullable`1 timeout, Boolean isSliding, CacheItemPriority priority, CacheItemRemovedCallback removedCallback, CacheDependency dependency) +825
        Umbraco.Core.CacheHelper.GetCacheItem(String cacheKey, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan timeout, Func`1 getCacheItem) +352
        umbraco.cms.businesslogic.cache.Cache.GetCacheItem(String cacheKey, Object syncLock, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem) +126
        umbraco.cms.businesslogic.cache.Cache.GetCacheItem(String cacheKey, Object syncLock, CacheItemRemovedCallback refreshAction, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem) +112
        Umbraco.Forms.Core.Services.CacheService.GetCacheItem(String cacheKey, Object syncLock, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem) +159
        Umbraco.Forms.Data.StringHelper.(String , Object ) +1621
        Umbraco.Forms.Data.StringHelper.ParsePlaceHolders(HttpContext Context, Record record, String value) +813
        Umbraco.Forms.Data.StringHelper.ParsePlaceHolders(HttpContext Context, String value) +62
        Umbraco.Forms.Core.Extensions.StringExtensions.ParsePlaceHolders(String text) +65
        Umbraco.Forms.Mvc.Models.FormViewModel.FetchDefaultValue(Field field) in f:\TeamCity\buildAgent\work\133677a4e37ceece\Umbraco.Forms.Mvc\Models\FormViewModel.cs:249
        Umbraco.Forms.Mvc.Models.FormViewModel.Build(Form form) in f:\TeamCity\buildAgent\work\133677a4e37ceece\Umbraco.Forms.Mvc\Models\FormViewModel.cs:143
        Umbraco.Forms.Web.Controllers.UmbracoFormsController.Render(Guid formId, Int32 recordId, String view, String mode) in f:\TeamCity\buildAgent\work\133677a4e37ceece\Umbraco.Forms.Mvc\Controllers\UmbracoFormsController.cs:33
    
  • marcelh 171 posts 471 karma points
    Aug 25, 2015 @ 08:02
    marcelh
    0

    Am I the only one running into this issue?

  • marcelh 171 posts 471 karma points
    Oct 26, 2015 @ 11:06
    marcelh
    0

    Kicking this up. Can't believe I'm the only one running into this issue. Does anyone get this working with Umbraco Forms? Using Contour this was no problem at all and I can't believe the dev team missed this.

    What I did notice is that lots of calls from the CacheService end in obsolete methods.

  • marcelh 171 posts 471 karma points
    Oct 30, 2015 @ 22:56
    marcelh
    0

    I've been digging into this today and finally found the cause. UmbracoForms at some moment in time loads all the member properties into the HttpRuntimeCache with the key umbrtmche-ContourMemberValues(memberId). In our scenario, we have a couple of customer member properties with editors that only display data. E.g. when, in the Umbraco Member section a member is viewed the a list of recent logins is displayed. Obviously, this editor does not persist any data. Another example is a button that is added as property editor to member that can be used to directly send the user his login credentials. It appears that UmbracoForms cannot handle these custom property editors. After removing these type of editors, all works as intended. After re-adding one of these property editors, bang.

    I digged into the cache, found the below exception for the mentioned key: enter image description here

    However, no solution found. Can the Umbraco Forms cachemechanism be instructed to only cache properties that are relevant?

  • marcelh 171 posts 471 karma points
    Nov 16, 2015 @ 09:34
    marcelh
    0

    For anyone running into this, I managed to solve the issue, with what I would call a "palliative". Or workaround.

    The issue is that we're using a bunch of custom property editors for a member that do not store a value, but rather act as a viewport to some custom datatables. The moment the-artist-formerly-known-as-contour reads a member's properties and stores them in the cache dictionary, these null values (which they are), are not accounted for. When retrieving the dictionary, this leads to the error message shown above.

    The palliative here is simple but effective. In the OnMemberSaving event of the MemberService, for any property that uses this kind of propertyeditor, a non-null value is set.

    private void OnMemberSaving(IMemberService sender, SaveEventArgs<IMember> e)
            {
                foreach (var member in e.SavedEntities)
                {
                    foreach (var p in member.PropertyTypes.Where(p => p.PropertyEditorAlias.StartsWith("Ults.")))
                    {
                        //NOTE: simply setting the value to an emtpy string is not enough, the value has to be "something"
                        if (member.GetValue(p.Alias) == null)                        
                            member.SetValue(p.Alias, p.PropertyEditorAlias);
                    }
                }
            }
    
  • Henning Molbaek 49 posts 99 karma points
    Nov 25, 2015 @ 08:08
    Henning Molbaek
    0

    Not sure I understand.

    Where do I add the workaround? Also, can the workaround be avoided if you have more complete members data? Again, not sure I understand what the issue is.

  • marcelh 171 posts 471 karma points
    Nov 25, 2015 @ 13:23
    marcelh
    0

    The issue is there when you have members with properties that can (potentially) be null. If this is the case, the caching mechanism that UmbracoForms uses to store and retrieve the member properties fails with a NullReferenceException.

    Using the workaround above, properties with null-values are assigned a value before a member is saved, so that these properties can be stored and retrieved succesfully from the cache.

    The complete code below:

    public class MemberEventHandler : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            base.ApplicationStarted(umbracoApplication, applicationContext);
    
            //NOTE: The runtime cache that umbraco keeps for members does not support NULL values
            //      The workaround for this is for any property that has a NULL value, the property is assigned a default value
            MemberService.Saving += OnMemberSaving;
        }
    
        private void OnMemberSaving(IMemberService sender, SaveEventArgs<IMember> e)
        {
            foreach (var member in e.SavedEntities)
            {
                foreach (var p in member.PropertyTypes.Where(p => p.PropertyEditorAlias.StartsWith("Ults.")))
                {
                    //NOTE: simply setting the value to an emtpy string is not enough, the value has to be "something"
                    if (member.GetValue(p.Alias) == null)                        
                        member.SetValue(p.Alias, p.PropertyEditorAlias);
                }
            }
        }
    }
    
  • Henning Molbaek 49 posts 99 karma points
    Nov 25, 2015 @ 13:28
    Henning Molbaek
    0

    Thanks for help.

    Where do I put this code?

  • David W. 159 posts 284 karma points c-trib
    Dec 10, 2015 @ 13:44
    David W.
    0

    Intresting find. Hopefully this will be fixed in a coming release.

    Question though. What does the "Ults." mean in your code snippet? Is it a namespace you use in your custom member properties?

  • marcelh 171 posts 471 karma points
    Dec 11, 2015 @ 15:58
    marcelh
    0

    Yup, hopefully it will. It's been bugging me a couple of months already...

    "Ults." is indeed the namespace that the propertyeditor starts with, in our case.

  • Matthew Kirschner 323 posts 611 karma points
    Sep 27, 2016 @ 18:32
    Matthew Kirschner
    0

    I noticed this happening even without default values if a member is simply signed in and submits a form.

  • marcelh 171 posts 471 karma points
    Sep 27, 2016 @ 18:40
    marcelh
    0

    Hey Matthew, can you confirm this occurs with the latest Umbraco Forms edition? I know that there has been an update released that should have solved this.

  • Matthew Kirschner 323 posts 611 karma points
    Sep 27, 2016 @ 18:58
    Matthew Kirschner
    0

    I'm using 4.3.2 (latest) with the new UI.

    I've also just checked the Changelog for versions 4.3.0+, and didn't see anything referencing this issue. Was this ever posted on the issue tracker?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 27, 2016 @ 19:30
    Dennis Aaen
    0

    Hi Metthew,

    Yes try to see this issue from the tracker http://issues.umbraco.org/issue/CON-841

    It has been fixed in next release of Umbraco Forms 4.3.3, which we are working hard to get out very soon.

    If you canĀ“t wait for the release, then you can always run the latest nightly build from here http://nightlies.s1.umbraco.io/?container=umbraco-forms-nightlies

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft