Copied to clipboard

Flag this post as spam?

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


  • Colin McFadden 4 posts 103 karma points
    Apr 30, 2021 @ 20:50
    Colin McFadden
    0

    Published Models not found - Umbraco 9 on .NET Core

    Hey everyone.

    I'm attempting to build out a simple site on Umbraco 9 and .NET Core, mainly for testing purposes.

    However, PublishedModels is behaving odd. I see the generated models under ~/umbraco/models/, but the razor views do not recognize PublishedModels.XXXX (i.e. @inherits UmbracoViewpage

    Does anyone know what I might be doing wrong? Or where in appsettings to change modelbuilder mode since I don't have web.config?

    I'd appreciate any help.

    EDIT: To be more thorough, the error is "The type for namespace 'Homepage' does not exist in 'Umbraco.Cms.Web.Common.PublishedModels'

  • Bjarke Berg 29 posts 265 karma points hq
    May 02, 2021 @ 18:25
    Bjarke Berg
    100

    Hi Colin..

    There's are few things to notice here: 1) The error you see is expected when using PureLive mode in ModelsBuilder. You should be able to build the solution, even when there are compile-time errors in views, if you have the following setting in the project file (Default when using the Umbraco templates):

    <!--Set this to true ModelsBuilder mode is not PureLive -->
    <PropertyGroup>
        <RazorCompileOnBuild>false</RazorCompileOnBuild>
    </PropertyGroup>
    

    2) The mode of the embedded ModelsBuilder can be changed in any of the JSON files using this code snippet:

    {
      "Umbraco": {
        "CMS": {
          "ModelsBuilder": {
            "ModelsMode": "AppData"
          }
        }
      }
    }
    

    Or you can change it from code, if you expect to use the same mode in all environments, by adding this to your Startup.ConfigureServices

    public void ConfigureServices(IServiceCollection services)
    {
       ...
       services.Configure<ModelsBuilderSettings>(options =>
       {
          options.ModelsMode = ModelsMode.AppData;
       });
    }
    

    BR/ Bjarke Berg

  • james whittington 19 posts 119 karma points c-trib
    May 04, 2021 @ 03:11
    james whittington
    0

    We had an issue where the models just would not work in the default location. (/umbraco/models), even custom classes we added here could not be discovered.

    You can change the default models location though the configuration settings to see if you are running into the same issue as we did.

     {
      "Umbraco": {
        "CMS": {
          "ModelsBuilder": {
            "ModelsMode": "AppData",
            "ModelsDirectory": "/whatever/path/"
          }
        }
      }
    }
    
  • Bjarke Berg 29 posts 265 karma points hq
    May 04, 2021 @ 06:20
    Bjarke Berg
    0

    Note that the default location is added as type None by default. You will need to add these as Content, like you did in v8, as soon as you use AppData.

    There is an up-for-grabs feature request about writing the Purelive models to another folder, so this folder could be Content by default. https://github.com/umbraco/Umbraco-CMS/issues/10213

  • Thobias Michel 18 posts 99 karma points
    Jun 03, 2021 @ 11:44
    Thobias Michel
    0

    Just a hint. the available ModelsMode are:

    namespace Umbraco.Cms.Core.Configuration
    {
    
      /// <summary>Defines the models generation modes.</summary>
      public enum ModelsMode
      {
        /// <summary>Do not generate strongly typed models.</summary>
        /// <remarks>
        /// This means that only IPublishedContent instances will be used.
        /// </remarks>
        Nothing,
        /// <summary>
        /// Generate models in memory.
        /// When: a content type change occurs.
        /// </summary>
        /// <remarks>The app does not restart. Models are available in views exclusively.</remarks>
        InMemoryAuto,
        /// <summary>
        /// Generate models as *.cs files.
        /// When: generation is triggered.
        /// </summary>
        /// <remarks>Generation can be triggered from the dashboard. The app does not restart.
        /// Models are not compiled and thus are not available to the project.</remarks>
        SourceCodeManual,
        /// <summary>
        /// Generate models as *.cs files.
        /// When: a content type change occurs, or generation is triggered.
        /// </summary>
        /// <remarks>Generation can be triggered from the dashboard. The app does not restart.
        /// Models are not compiled and thus are not available to the project.</remarks>
        SourceCodeAuto,
      }
    }
    
  • Francis Pion 3 posts 83 karma points
    Aug 06, 2021 @ 18:33
    Francis Pion
    0

    Yes! Am I the only one who cannot set the ModelsMode to AppData?

    I get the warning:

    Value must be one of the following values: "Nothing", "InMemoryAuto", "SourceCodeManual", "SourceCodeAuto"
    

    Bjarke Berg is suggesting to use this mode but now it doesn't build.

    Best regards!

  • Bjarke Berg 29 posts 265 karma points hq
    Aug 06, 2021 @ 18:36
    Bjarke Berg
    2

    The modes has been renamed:

    InMemoryAuto = PureLive
    SourceCodeManual = AppData
    SourceCodeAuto = LiveAppData
    
  • Marco Graziotti 40 posts 166 karma points c-trib
    Sep 17, 2021 @ 17:13
    Marco Graziotti
    0

    Hi,

    I'm using the Umbraco 9 RC3 and I still have this problem.

    The RazorCompileOnBuild is set to false, and in the "appsettings.json" I have configured the Models Builder as AppData, using the keyword SourceCodeManual and generated the models, but the classes cannot be used inside the code because the namespace Umbraco.Cms.Web.Common.PublishedModels.{My_Class_Name} can't be found.

    Do anyone has this problem?

    Thank you, Marco

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Sep 18, 2021 @ 06:36
    Marc Goodson
    0

    Hi Marco

    AppData is no more... (as there is no App Data folder!)

    The setting has been renamed to be 'SourceCodeManual'

    to manually generate the models into source code... (eg then needs to be compiled and so generated files will need to be included in the VS solution at the path they are generated)

    so try setting

     "ModelsMode": "SourceCodeManual",
    

    in your json configuration file.

    regards

    Marc

  • Marco Graziotti 40 posts 166 karma points c-trib
    Sep 20, 2021 @ 13:05
    Marco Graziotti
    0

    Hi Marc,

    thank you for your reply.

    I have already tried to set "ModelsMode" to "SourceCodeManual", without success, the autogenerated classes cannot be used inside the code because the namespace Umbraco.Cms.Web.Common.PublishedModels.{My_Class_Name} can't be found.

    Here is the list of the parts that I have checked:

    • inside the .csproj file the "RazorCompileOnBuild" is set to "false";
    • the property "ModelsMode" in the "appsettings.json" file is set to "SourceCodeManual";

    What I noticed is that also for the class PublishedContentModel the "go to" key (F12 in Visual Studio) is not working. Here a screenshot where you can see the class "PublishedContentModel" in white color instead of green color. That's a strange behavior.

    enter image description here

    Does anyone have this problem?

    Thank you, Marco

  • Eugene 1 post 71 karma points
    Jun 12, 2022 @ 06:22
    Eugene
    0

    I think I have the same problem with Umbraco 9.5.1 freshly installed. Intellisense does not work in cshtml views. After I set the following option:

    "CMS": {
      "CopyRefAssembliesToPublishDirectory": true,
      "ModelsBuilder": {
        "ModelsMode": "SourceCodeManual",
        "ModelsDirectory": "/umbraco/models"
    

    It gives me "The type or namespace name 'Test' does not exist in the namespace 'Umbraco.Cms.Web.Common.PublishedModels' (are you missing an assembly reference?)"

    No matter if I enter "/umbraco/models", "umbraco/models" or "~/umbraco/models", models folder is empty except for the file ood.flag. (what's the difference between these paths anyway?)

    CopyRefAssembliesToPublishDirectory flag was added following a hint in error message but didn't help.

    PS: PROBLEM SOLVED by going to Settings -> Models Builder and regenerating models.

Please Sign in or register to post replies

Write your reply to:

Draft