Copied to clipboard

Flag this post as spam?

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


  • Jo Kendal 32 posts 194 karma points
    Feb 26, 2019 @ 16:11
    Jo Kendal
    0

    Models Builder Issue in Umbraco 8

    Just starting to play with Umbraco 8 and I am getting errors in the generated models for Umbraco 8

    Error:

    'File' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'File' could be found (are you missing a using directive or an assembly reference?) 
    

    This error occurs for all models generated that use the syntax this.Value

    e.g.

        ///<summary>
        // Width: in pixels
        ///</summary
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder", "8.0.1")]
        [ImplementPropertyType("umbracoWidth")]
        public int UmbracoWidth => this.Value<int>("umbracoWidth");
    

    I notice in Umbraco 7 the same portion of model code is

    ///<summary>
    /// Width
    ///</summary>
    [ImplementPropertyType("umbracoWidth")]
    public string UmbracoWidth
    {
        get { return this.GetPropertyValue<string>("umbracoWidth"); }
    }
    

    The models builder configuration in the web.config is:

    <add key="Umbraco.ModelsBuilder.Enable" value="true" />
        <add key="Umbraco.ModelsBuilder.ModelsMode" value="AppData" />
        <add key="Umbraco.ModelsBuilder.ModelsDirectory" value="~/../Umbraco.Web.PublishedContentModels" />
        <add key="Umbraco.ModelsBuilder.AcceptUnsafeModelsDirectory" value="true" />
    

    We follow the same pattern successfully for all our Umbraco 7 sites - we use a 3 project solution

    Umbraco.Web.PublishedContentModels - with references to Umbraco.Core and Umbraco.ModelsBuilder and System.Web

    xyz.Core - with reference to project Umbraco.Web.PublishedContentModels

    xyz.Web - with reference to project Umbraco.Web.PublishedContentModels

    Out of the box the only model that does not throw an error and allows compilation is the default folder model - as this contains no properties to return.

    Any ideas anyone?

  • louisjrdev 107 posts 344 karma points c-trib
    Feb 26, 2019 @ 20:08
    louisjrdev
    0

    im having this issue too

  • Jo Kendal 32 posts 194 karma points
    Feb 27, 2019 @ 14:03
    Jo Kendal
    0

    My colleague is also having this issue too.

    He drilled into it further and found that calls to Model.Value<xyz>("abc") are also not working in the views. Yet the intellisense is there. Strangely he also noted that although Model.Value("abc"), that is iPublishedContent , appears to work but yet is not in intellisense.

    May raise on issue tracker.

  • louisjrdev 107 posts 344 karma points c-trib
    Feb 27, 2019 @ 14:05
    louisjrdev
    0

    A colleague at my company suggested it was something odd happening with the nuget packages and he had to install them in a specific order:

    The core package

    Then the models builder packages

    I think you also need to watch out for missing references to System.Web

  • Jo Kendal 32 posts 194 karma points
    Feb 27, 2019 @ 14:43
    Jo Kendal
    0

    Hi I tried that but no luck.

    I have raised an issue here: https://github.com/umbraco/Umbraco-CMS/issues/4780

  • Damian 74 posts 397 karma points
    Feb 28, 2019 @ 00:46
    Damian
    102

    I resolved this issue in my new v8 (!) project by ensuring the projects Target Framework was v4.7.2

    I realized the discrepancy between intellisense in the project and the actual runtime behaviour and so checked what the umbraco v8 dlls are compiled against and that is, indeed, v4.7.2

    hope this helps!

  • louisjrdev 107 posts 344 karma points c-trib
    Feb 28, 2019 @ 12:41
    louisjrdev
    8

    I resolved this by ensuring i installed the Umbraco.Web nuget package in my project where the generated models exist

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Jun 17, 2019 @ 10:05
    Simon Dingley
    1

    Correct - thanks for posting this!

    I think for anyone generating models in their Web project it wouldn't be an issue but I guess you are, like me, generating them in a separate class project so not all UmbracoCms package dependencies are present.

  • Mike Chadwick 41 posts 182 karma points
    Oct 02, 2019 @ 09:54
    Mike Chadwick
    0

    Spot on! This solved it for me too.

  • javafun 17 posts 50 karma points c-trib
    Jun 04, 2022 @ 13:06
    javafun
    0

    This works as expected. The value method exists in PublishedContentExtensions under Umbraco.Web assembly.

Please Sign in or register to post replies

Write your reply to:

Draft