Copied to clipboard

Flag this post as spam?

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

  • Martin 7 posts 89 karma points
    Jul 22, 2019 @ 08:21

    Modelsbuilder - using umbraco types in custom code

    I tried posting this question before but it has rendered unreadable so I try again.

    I believe my problem originates from a lack of understanding how Modelsbuilder and strong types are to be used/configured. I'm new to Umbraco so the following is my best guess:

    I've created DocumentTypeS (HeaderMenu and Footer) with a Template and corresponding Content and wish to use this type in backend custom code. My basic layout for the site is (_Layout.cshtml which is Layout for content Home):

            @{Html.RenderAction("RenderLogin", "Login"); }
            @{Html.RenderAction("RenderHeader", "HeaderMenu", new {model = Model}); } 
           @{Html.RenderAction("RenderFooter", "Footer", new {model = Model}); } 

    In Web.config I set:

    And in App_Data/Models/ I've included like so:


    I know have the following in\App_Data\TEMP\TypesCache:

    Umbraco.Web.PublishedModels.Footer, Umbraco.Web.PublishedModels, Version=, Culture=neutral, PublicKeyToken=null Umbraco.Web.PublishedModels.HeaderMenu, Umbraco.Web.PublishedModels, Version=, Culture=neutral, PublicKeyToken=null ... Umbraco.Web.PublishedModels.Footer, MyNameSpace, Version=, Culture=neutral, PublicKeyToken=null Umbraco.Web.PublishedModels.HeaderMenu, MyNameSpace, Version=, Culture=neutral, PublicKeyToken=null

    which I suspect is the reason for the following error when starting umbraco:

    Boot failed: Umbraco cannot run. See Umbraco's log file for more details.

    Umbraco.Core.Exceptions.BootFailedException: Boot failed. System.InvalidOperationException: Unable to resolve type: Umbraco.Core.Composing.ComponentCollection, service name: at LightInject.ServiceContainer.CreateDelegate(Type serviceType, String serviceName, Boolean throwError) in C:\projects\lightinject\src\LightInject\LightInject.cs:line 4748 at LightInject.ServiceContainer.CreateDefaultDelegate(Type serviceType, Boolean throwError) in ...

    Where it, e.g., says the following in the log file:

    Both types 'Umbraco.Web.PublishedModels.Footer, MyNameSpace, Version=, Culture=neutral, PublicKeyToken=null' and 
           'Umbraco.Web.PublishedModels.Footer, Umbraco.Web.PublishedModels, Version=, Culture=neutral, PublicKeyToken=null' want to be a model type for content type with alias \"footer\".\r\n

    I've also experimentet with Dll mode but I get various errors depending on configuration settings and what I include where. No combination so far seems to give me what I want, which is basically strong types in the backend and a site that can boot!

    Any help and suggestions will be much appreciated!

    Thank you!

  • Jonathan Distenfeld 105 posts 615 karma points
    Jul 23, 2019 @ 08:17
    Jonathan Distenfeld

    Hi Martin,

    it looks like your site failes to boot because there are multiple models in your backend having different namespaces but have the same alias. I assume you created the models, changed the namespace and created it again. Please try to delete unnecessary models and make sure Footer and HeaderMenu only exist once. After that, your site should boot properly.

    If you wan't to know how to use strongly typed models in Umbraco, please take a look at the documentation: .

    ~ Jonathan

  • Martin 7 posts 89 karma points
    Jul 23, 2019 @ 08:54

    Hi Jonathan

    Thank you very much for your reply. I did read the documentation but had a few things I didn't quite understood - go figure! :)

    I suppose (?!) the mistake was to include the *generated.cs-files so I ended up starting over and went for the Dll mode. This seems to work, and due to the reference, I suppose, the types are now present only once.

    Also, I ended up installing 8.1.0 (I'm on 8.0.2 right now), took a look at the example site, and reconfigured my templates. I now have a much simpler setup and have "strong" access to my types.

    Thanks again!


  • Alan Mitchell 42 posts 233 karma points c-trib
    Jul 23, 2019 @ 09:04
    Alan Mitchell

    This is related ... but different. Apologies for the hijack.

    I found this thread because I was searching for recent issues with the ModelsBuilder. Just started a new project, Umbraco Cloud and it looks like we're the unwitting guinea pigs with 8.1. Had real troubles generating models - breaking templates etc. Found the answer here:

    TLDR: If you use API mode to build models to an external project - which is the recommended approach for cloud I believe - you should follow this guide - but use the new Extension (not custom tool) which has only been released on Friday.

    It works, well done everybody for getting things fixed, but I spent a lot of time chasing around old misleading documentation - there has to be a better way of communicating breaking changes for such core things?

  • Martin 7 posts 89 karma points
    Jul 23, 2019 @ 09:09

    I also tried the custom tool solution and must have experienced the same problems you are hinting at. Thank you very much for pointing out the Extension!

Please Sign in or register to post replies

Write your reply to: