Copied to clipboard

Flag this post as spam?

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


  • Tom Norwood 29 posts 60 karma points
    Aug 23, 2015 @ 14:00
    Tom Norwood
    0

    NullReferenceException in UpdateRecordField

    Hi

    I'm seeing an exception after submitting a form in Umbraco Contour. I'm running a nightly build:

    http://nightly.umbraco.org/UmbracoForms/nightlies/UmbracoForms.Files.4.2.0-WIP.Build.65.zip

    [NullReferenceException: Object reference not set to an instance of an object.] Umbraco.Forms.Data.Storage.RecordFieldStorage.UpdateRecordField(RecordField recordField) +163 Umbraco.Forms.Data.Storage.RecordStorage.UpdateRecord(Record record, Form form) +821 Umbraco.Forms.Web.Services.RecordService.storeRecord(Record record, Form form) +216 Umbraco.Forms.Web.Services.RecordService.Approve(Record record, Form form) +157 Umbraco.Forms.Web.Services.RecordService.Submit(Record record, Form form) +366

    More details, fiddler trace and the form JSON are here: http://issues.umbraco.org/issue/CON-816

    Thanks!

    Tom

  • Breakfast 5 posts 76 karma points
    Feb 26, 2016 @ 17:34
    Breakfast
    1

    I ran into this too and it was to do with the "Field" property of the RecordField that it was trying to update. In fact it was trying to update the "Page" subtype, which I'm pretty sure isn't supposed to be updated?

    Either way, if you run this against your record before you call UpdateRecord, that will crash out to tell you what is popping a null in the relevant field and you can tinker around with it:

                foreach ( KeyValuePair<Guid, RecordField> kvp in record.RecordFields )
                {
    
                    if ( kvp.Value.Key != Guid.Empty )
                    {
                        var recordField = kvp.Value;
                        Trace.TraceInformation($"Field Id: {recordField.Field.Id}");
                        Trace.TraceInformation($"Record: {recordField.Record}");
                        Trace.TraceInformation($"DataType: {recordField.Field.FieldType.DataType.ToString()}");
                        Trace.TraceInformation($"DataType: {recordField.Key}");
                    }
                }
    

    Of course if you're using the regular built-in Forms controller there's not a lot you can do with it unfortunately. If the problem shows up in multi-page forms this is probably a bug in the way Forms handles pages.

  • Matthew Kirschner 312 posts 562 karma points
    1 week ago
    Matthew Kirschner
    0

    This helped me a ton, thanks!

    I had an issue where I was getting a null object reference whenever I tried to update a record (I'm assuming because the form had since changed). The solution was to loop through the RecordFields and remove any that had a null Field:

    foreach (var kvp in rec.RecordFields.ToList())
    {
        if (kvp.Value.Key != Guid.Empty)
        {
            var recordField = kvp.Value;
            if (recordField.Field == null)
            {
                rec.RecordFields.Remove(kvp.Key);
            }
        }
    }
    
    rs.UpdateRecord(rec, form);
    
Please Sign in or register to post replies

Write your reply to:

Draft