Copied to clipboard

Flag this post as spam?

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


  • Tony Bolton 4 posts 74 karma points
    Feb 28, 2021 @ 17:23
    Tony Bolton
    0

    Object reference not set to an instance of an object. (Formulate)

    Hi,

    Sorry to bother you.

    I'm just trying out Formulate on an Umbraco 8.11.1 site, and having followed the instructions finally added the call to render the form.

    However, when it tries to render, it errors with the following stack trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       formulate.api.Controllers.FormulateRenderingController.Render(ConfiguredFormInfo form) in D:\r\formulate\src\formulate.api\Controllers\FormulateRenderingController.cs:46
       lambda_method(Closure , ControllerBase , Object[] ) +104
       System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
    

    I've boiled it down to the form picker - when I look at the property type for Model.ContactForm, which I'm using as follows:

    @Html.Action("Render", "FormulateRendering", new { form = Model.ContactForm })
    

    It tells me that the type is System.String, and that the content is :

    formulate.app.Types.ConfiguredFormInfo

    Taking at a look at the source in github I can see the type expected is as above. It's almost as if the data picker when I selected the form has taken the type name and stored it as a string in the document.

    Any ideas? Would appreciate any help or pointers - I must have missed something or done something stupid during the setup.

    Thanks in advance!

    Tony

    edit #1 : Some extra info for you. If I cast it, I get the following:

    formulate.app.Types.ConfiguredFormInfo form = (formulate.app.Types.ConfiguredFormInfo)Model.ContactForm;
    
    Cannot convert type 'string' to 'formulate.app.Types.ConfiguredFormInfo'
    

    Also, I thought I'd check the backend and see what Umbraco believed was stored against the field, and to be honest it 'looks' ok to me:

    "contactForm":[{"v":"{\r\n  \"id\": \"6aec1f9220974920a474959e714c0832\"\r\n}"}]
    

    I'm using the LiveAppData for the models so that the intellisense worked in VS. Looking at the ContactForm model, it has persisted it as an object:

            ///<summary>
            /// Contact Form
            ///</summary>
            [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "8.11.1")]
            [ImplementPropertyType("contactForm")]
            public object ContactForm => this.Value("contactForm");
    

    Thought this might help point out anything obvious to the trained eye.

    Edit #2:

    Ok getting somewhere now. If I switch to PureLive for the model builder, it's rendering the form fields. So I guess the question now is can I use formulate with the LiveAppData model, or is it only compatible with PureLive?

    Cheers!

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Feb 28, 2021 @ 21:37
    Nicholas Westby
    0

    Thanks for including so much detail with your post; really helps.

    Interestingly, I have Formulate (version 3.2.1, which is a bit outdated) working on an Umbraco 8.11.1 site, and I'm using LiveAppData as the ModelsBuilder mode:

    <add key="Umbraco.ModelsBuilder.Enable" value="true" />
    <add key="Umbraco.ModelsBuilder.ModelsMode" value="LiveAppData" />
    <add key="Umbraco.ModelsBuilder.ModelsNamespace" value="MyWebsite.Application.Models.PublishedContentModels" />
    <add key="Umbraco.ModelsBuilder.ModelsDirectory" value="~/../Application/Models/PublishedContentModels/GeneratedCode" />
    <add key="Umbraco.ModelsBuilder.AcceptUnsafeModelsDirectory" value="true" />
    

    The type in my case is also set to be an object for the generated property:

    ///<summary>
    /// Form
    ///</summary>
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder", "8.1.6")]
    [ImplementPropertyType("form")]
    public object Form => this.Value("form");
    

    Note that in my case we're using Block List as the property type for widgets, but block list uses doctypes for each widget, so it should be pretty similar to putting a property directly on a doctype for a page.

    Here you can see the doctype I have configured for my widget:

    Form Widget Doctype

    I'll try upgrading my install of Formulate to the latest version and try to replicate the issue. Here are some other things to check on:

    • Be sure you've actually chosen the form. When choosing a form, you really choose a form configuration, which is an object that exists in the tree underneath the form.
    • Be sure you have the form/form configuration/layout/template all properly chosen.
    • Check if you have any extra plugins installed (especially any plugins that have custom property value converters).

    BTW, how did you check the backend to see what Umbraco believed was stored against the field? Perhaps I can check what is stored on my end as well to see if it looks similar.

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Feb 28, 2021 @ 22:08
    Nicholas Westby
    0

    I've just upgraded to Formulate 3.5.0 (the latest version) and still haven't been able to reproduce the issue. It's a strange one for sure. Can you try switching back to LiveAppData and see if the issue still exists?

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Feb 28, 2021 @ 22:19
    Nicholas Westby
    0

    I may have one clue. Here's how the form property is stored for me, according to the cmsContentNu table:

    "form": "{\r\n  \"id\": \"15719781b1a34bc9b7fc3dedb2973536\"\r\n}",
    

    This differs from your example a bit. For examples, your example has an array and a "v" key, while my example does not.

    Here the property is within the broader widget context:

    {
      "layout": {
        "Umbraco.BlockList": [
          {
            "contentUdi": "umb://element/1f94ca32b3af4bbe93cd418482e1213a",
            "settingsUdi": "umb://element/3220dfe4729448168d457a087ecfed26"
          }
        ]
      },
      "contentData": [
        {
          "contentTypeKey": "42cda343-7560-4e3f-8df9-f83c50399dc1",
          "udi": "umb://element/1f94ca32b3af4bbe93cd418482e1213a",
          "header": "<p>Some Header Here</p>",
          "form": "{\r\n  \"id\": \"15719781b1a34bc9b7fc3dedb2973536\"\r\n}",
          "successContent": "{\"layout\":{\"Umbraco.BlockList\":[{\"contentUdi\":\"umb://element/95145a7dac96475a94278f2950804bbe\",\"settingsUdi\":\"umb://element/73c843f89c134da88bd7afa58a9fed4d\"}]},\"contentData\":[{\"contentTypeKey\":\"3df89656-2b6f-4e0a-a441-51b58d48d7ae\",\"udi\":\"umb://element/95145a7dac96475a94278f2950804bbe\",\"richText\":\"<p>Yay! It worked!</p>\"}],\"settingsData\":[{\"contentTypeKey\":\"82891286-2e68-4471-b3a6-5f5e6bef2787\",\"udi\":\"umb://element/73c843f89c134da88bd7afa58a9fed4d\",\"isDisabled\":\"0\"}]}",
          "failureContent": "{\"layout\":{\"Umbraco.BlockList\":[{\"contentUdi\":\"umb://element/247cf39d62c34319a498f4647ba78f00\",\"settingsUdi\":\"umb://element/19771474d5584797b362f23ccf1594ec\"}]},\"contentData\":[{\"contentTypeKey\":\"3df89656-2b6f-4e0a-a441-51b58d48d7ae\",\"udi\":\"umb://element/247cf39d62c34319a498f4647ba78f00\",\"richText\":\"<p>Darn! It failed!</p>\"}],\"settingsData\":[{\"contentTypeKey\":\"82891286-2e68-4471-b3a6-5f5e6bef2787\",\"udi\":\"umb://element/19771474d5584797b362f23ccf1594ec\",\"isDisabled\":\"0\"}]}"
        }
      ],
      "settingsData": [
        {
          "contentTypeKey": "a22f4c3f-a163-4371-929f-bb05c4ced1dc",
          "udi": "umb://element/3220dfe4729448168d457a087ecfed26",
          "isDisabled": "0",
          "label": ""
        }
      ]
    }
    

    There is an even broader page context, but I stripped that out since it didn't seem important.

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Feb 28, 2021 @ 22:22
    Nicholas Westby
    0

    One thought I just had is that the Umbraco variants feature may have some impact on this. My guess is that's why you have a "v" property in your data. Not really sure, but thought I'd mention it just in case it's of use.

  • Tony Bolton 4 posts 74 karma points
    Mar 05, 2021 @ 09:31
    Tony Bolton
    0

    Hi Nicholas,

    Thanks so much for the response - sorry I've not replied sooner - work commitments :|

    I'll take a look this weekend and get back to you once I've done some tests. Thanks again, it's much appreciated,

    Tony

  • Tony Bolton 4 posts 74 karma points
    Mar 13, 2021 @ 13:21
    Tony Bolton
    0

    Hi Nicholas,

    Finally had time to look at this again. I noticed I was missing the Umbraco.ModelsBuilder.ModelsDirectory in the web.config file - which to be honest I didn't think would matter.

    Regardless I popped it in, rebuilt and generated the models as well as switched back to LiveAppData mode, and it seems to be working now.

    Very odd, as the data in cmsContentNu is still the same:

    "contactForm":[{"v":"{\r\n  \"id\": \"6aec1f9220974920a474959e714c0832\"\r\n}"}]
    

    It's looking much better now - it's certainly rendering the form properly!

    Now onto customising the styles :)

    Thanks again, Tony

Please Sign in or register to post replies

Write your reply to:

Draft